SRL Archive - Help and Support

Splitting strings help!


R0b0t1

2007-10-09 18:48:16

Well, what I am trying to do is add to a string (In a loop), but every 6 characters I want to add a space. The reason I'm asking for help though is because my loop adds 8 characters at a time…


Any suggestions?



EDIT: Only thing I've found is that it goes in a pattern:

From: notepad
123456 781234 567812 345678 123456 781234

Smartzkid

2007-10-09 18:49:40

Space it with a seperate loop?

R0b0t1

2007-10-09 18:50:47

I, is, dumb.



EDIT: Can you help me space it with a loop? I can't get it right!

Jason2gs

2007-10-10 16:35:41

This seems to work:

procedure TestSpace;
var
i: Integer;
j: Integer;
Str: String;
begin
j := 1;
Str := '123456123456123456123456123456123456123456123456123456123456';
for i := 1 to Length(Str) do
begin
j := j + 1;
if (i mod 6) = 0 then
begin
Insert(' ', Str, j);
j := j + 1;
end;
end;
Writeln(Str);
end;

R0b0t1

2007-10-10 16:54:18

OmG! No fair! Yours works right!


I did almost the exact same thing and it didn't work…

Oh, BTW, Thanks.

Jason2gs

2007-10-10 17:08:13

I tried something like it last night, except without the extra integer in there, and it didn't work either.

Not quite sure why.

And Np ;)

R0b0t1

2007-10-10 18:53:36

Man! it only works for strings a certain length… Damnit!



EDIT: I mean when I try to add more than one character, like


Insert('*'+IntToStr(SomeNum)+'*', ...)

Jason2gs

2007-10-10 22:00:14

Hmm…

procedure TestSpace;
var
Str: String;
i, j: Integer;
InsertString: String;
begin
j := 1;
Str := '123456123456123456123456123456123456123456123456123456123456';
for i := 1 to Length(Str) do
begin
j := j + 1;
if (i mod 6) = 0 then
begin
InsertString := '___';
Insert(InsertString, Str, j);
j := j + Length(InsertString);
end;
end;
Delete(Str, Length(Str) - Length(InsertString), Length(InsertString)); // Don't work? :(
while Pos(InsertString + InsertString, Str) <> 0 do
begin
Str := Replace(Str, InsertString + InsertString, InsertString);
end;
Writeln(Str);
end;

Works, and takes care of most of the extra characters at the end. 'Cept for three at the end that just won't go away for me :|

R0b0t1

2007-10-11 20:59:34

OMG! You… Are… Awesome!


I've never actually had someone answer so many things… Wait… Do I have mind control? :p

Jason2gs

2007-10-12 09:07:48

From: R0b0t1
OMG! You… Are… Awesome!


I've never actually had someone answer so many things… Wait… Do I have mind control? :p


I… Don't know :O

*Starts taking off pants*

Hey! Stop it!