Hi
Donovan
I
assume you are trying to normalise out common data.
Question 1
The
simplest way is as a TStringList if the Player IDs are not contiguous - thsi
handles non-existant IDs and a lot of hastles. If the IDs are a contiguous
list and will always exist you can use an array of string.
Question 2
My
main comment is that I would use a unique marker or tag to mark the start
and end of insert points. Choose a pair of ASCII constants < 32 such as
STX/ETX or if they must be printable use '<<' '>>' or '[' ']' -
anything that will not occur in normal use.
Somthing like
Var
s : String;
StartPos, EndPos, TagValue : Integer;
Players : TStringList;
Const
StartMarker = '[';
EndMarker = ']';
begin
.....
while pos(StartMarker, s) > 0 do
begin
StartPos := pos(StartMarker,
s);
EndPos := pos(EndMarker,
s);
if EndPos = 0
then // Skip if markers unbalanced
Exit;
TagValue := StrToIntDef(Copy(s, StartPos + Length(StartMarker),
(EndPos - StartPos - Length(StartMarker)), -1);
if TagValue = -1 then // Skip is not a valid
tag
Exit;
Delete(s, StartPos, (EndPos - Start
Pos + Length(EndMarker));
Insert(Players.Values[IntToStr(TagValue)], s, StartPos);
end;
......
Result := s;
end;
E&OE :)
Stephen
-----Original Message-----
From: Donovan
J. Edye [mailto:[EMAIL PROTECTED]]
Sent: Friday, 13 July 2001 5:12
p.m.
To: Multiple recipients of list delphi
Subject: [DUG]:
How to approach this?
All,
I have to do the following:
- Replace some numeric integers with string values in a string
- The position of the integers the string may vary
- It all has to be as fast as possible
What we have are some paradox tables with the following format: (TPlayerID : integer)
TableA
PlayerID : TPlayerID
FirstName : string;
SecondName : string;
TableB
BatsmanID : TPlayerID
BowlerID : TPlayerID
Field1
Field2
Field3
OtherBatsmanID : TPlayerID
Field4
etc.
Assume we have the following TPlayerID - TPlayerCode mappings. TPlayerCode : string[5]
1 - ABCDE
2 - FGHIJ
3 - MNOPQ
etc.
If we get strings as follows - say read from a text file:
PlayerID, FirstName, SecondName
3,John,Doe
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
1,3,a,b,c,2,e
PlayerID, FirstName, SecondName
1,Paul,Smith
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
2,1,a,b,c,3,e
Question 1:
- What is the most efficient way to store the TPlayerID, TPlayerCode as a memory structure mappings so that:
- Minimal memory footprint
- Fastest searching
The above mappings list does not generally change a lot. So "slow" creation of the mapping list is not a big concern. Typically the mapping list is created once and accessed many. It is nominally read only.
Question 2:
- What is the most efficient way to replace a specific string with another? So given:
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
1,3,a,b,c,2,e
End up with
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
ABCDE,MNOPQ,a,b,c,FGHIJ,e
Comments, suggestions welcome. TIA-- Donovan
----------------------------------------------------------------------
Donovan J. Edye [www.edye.wattle.id.au]
Namadgi Systems [www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------