Anton007
asked on
Need help with editing strings in a stringList
I have to open a text file read in each line into a TStringList.
Then I have to make changes to each string in the TListdtring
and write the chnaged strings to a list box.
Sample of the sting:
PART,1572315-111B,,,1,,157 2315-111B, 6
What I have to changes:
After the 1st comma I must insert ss1
After the 2nd comma I must insert ss2
After the 3rd comma I must insert ss3
and the 2nd last string must be 1572315-111B.cdl
The final string must look like this:
PART,1572315-111B,ss1,ss2, 1,ss3,1572 315-111B.c dl,6
I got this far:-
var
MyString : TStringList;
i : integer;
begin
Mystring := TStringList.Create;
Mystring.LoadFromFile('C:\ Test.txt);
for i := 0 to Mystring.Count-1 do
listbox2.Items.Assign(Myst ring);
Then I have to make changes to each string in the TListdtring
and write the chnaged strings to a list box.
Sample of the sting:
PART,1572315-111B,,,1,,157
What I have to changes:
After the 1st comma I must insert ss1
After the 2nd comma I must insert ss2
After the 3rd comma I must insert ss3
and the 2nd last string must be 1572315-111B.cdl
The final string must look like this:
PART,1572315-111B,ss1,ss2,
I got this far:-
var
MyString : TStringList;
i : integer;
begin
Mystring := TStringList.Create;
Mystring.LoadFromFile('C:\
for i := 0 to Mystring.Count-1 do
listbox2.Items.Assign(Myst
ASKER
Hi Shane
Thanks for that.
The strings are not the same length, What must i do then?
Thanks
Anton
Thanks for that.
The strings are not the same length, What must i do then?
Thanks
Anton
Cut & paste me an example of the trings (lets say 10 records), showing the difference and I will work something up for you
Shane
Shane
ASKER
PART,1572315-112251B, ,,1,,1572315-112251B,6
PART,157231533-111C, ,,1,,157231533-111C,7
PART,1572315-11B, ,,1,,1572315-11B,68
PART,157231533-111XC, ,,1,,157231533-111XC,7
Thanks for the help
OK, i'll see what i can do...
Shane
Shane
is there always a number 1 here
PART,1572315-112251B, ,, -----> 1 < ----- ,,1572315-112251B,6
Shane
PART,1572315-112251B, ,, -----> 1 < ----- ,,1572315-112251B,6
Shane
ASKER
No, That "1" represents a qty. So that can be any number
Anotn
Anotn
K
Shane
Shane
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Shane, Your the MAN!!!!!!!!!!!!!!!!!!!!!!!
Worked perfectly
Thank you!!
Cheers
Anton
<SMILE>
Im glad it worked!
Shane
var
MyStringList : TStringList;
I, J: integer;
tmpStr: String;
begin
MyStringList := TStringList.Create;
MyStringList.LoadFromFile(
for I := 0 to MyStringList.Count-1 do
begin
tmpStr:= MyStringList[I];
Insert('ss1', tmpStr, 19);
Insert('ss2', tmpStr, 23);
Insert('ss3', tmpStr, 29);
Insert('.cdl', tmpStr, 45);
MyStringList[I]:= tmpStr;
end; //for I
MyStringList.Free;
end;
Shane