SRL Archive - OSR Help

Quick question, cookie rewarded :3


Bionicle

2010-04-02 18:52:44

Is there any way to remove the spaces from a string?

Timer

2010-04-02 18:53:25

program New;
var
s: string;

begin
s := Replace('This work?', ' ', '');
writeln(s);
end.

Blumblebee

2010-04-02 18:53:38

explode(s, ' ') or something like that?

Bionicle

2010-04-02 18:56:13

From: Timer
program New;
var
s: string;

begin
s := Replace('This work?', ' ', '');
writeln(s);
end.


Thank you!
(btw u had it backwards, it would be s := Replace('This work', ' ', ''); :p)

Mario cookie 4 u, nom nom.

Timer

2010-04-02 18:56:50

From: bionicle1800
Thank you!
(btw u had it backwards, it would be s := Replace('This work', ' ', ''); :p)

Mario cookie 4 u, nom nom.


Isn't that how I had it? :o

EDIT: If you wanna do something cool, like Blumbebee said–
program New;
var
s: string;
ss: TStringArray;
i, h: Integer;

begin
s := 'Lets blow this bitch up!';
ss := Explode(' ', s);
h := High(ss);
for i := 0 to h do
WriteLn(ss[i]);
end.

Nava2

2010-04-02 19:22:50

Or just trim..

Bionicle

2010-04-02 19:33:51

From: Nava2
Or just trim..


Thanks, but Replace worked perfectly :)
I had a number to a string with spaces, but it wouldn't convert to an integer unless the spaces were gone. I was working price checking functions if you want to take a look at it:
http://villavu.com/forum/showthread.php?p=699269#post699269

Frement

2010-04-02 20:16:42

From: Nava2
Or just trim..


Doesnt trim remove the left and right space?

Dgby714

2010-04-02 20:18:12

From: Frement
Doesnt trim remove the left and right space?


Yes, Trim wouldn't remove spaces if there in the middle of a string =)

Frement

2010-04-02 20:20:00

From: Dgby714
Yes, Trim wouldn't remove spaces if there in the middle of a string =)


Yes I know that :) Just correcting it would be kind of rude, so i put it in a form of a question thought i didnt need an answer ;)

i luffs yeww

2010-04-02 20:45:52

How is correcting a mistake being rude? He might've meant TrimOthers, which would work if the string he wanted was only alphanumerical characters.

Nava2

2010-04-03 00:53:10

From: i luffs yeww
How is correcting a mistake being rude? He might've meant TrimOthers, which would work if the string he wanted was only alphanumerical characters.


That was what I meant, or you could use getNumbers todo theoretically the same thing.

mixster

2010-04-03 05:33:29

s := srl_Implode(srl_Explode('oh meow?', ' '), '');

Dunno what timer was doing with that looping silliness…

i luffs yeww

2010-04-03 11:10:21

Silly, mixster. There's only two parameters each function!


{.include SRL/SRL.scar}
var
s: string;

begin
SetupSRL;
s := srl_Implode(srl_Explode('oh meow?', ' '), '');
Writeln(s);
end.

Gu3st...

2010-04-03 11:25:11

From: i luffs yeww
Silly, mixster. There's only two parameters each function!


{.include SRL/SRL.scar}
var
s: string;

begin
SetupSRL;
s := srl_Implode(srl_Explode('oh meow?', ' '), '');
Writeln(s);
end.
Silly, i luffs yeww. There's no need for SetupSRL; there!

{.include SRL/SRL.scar}

begin
Writeln(srl_Implode(srl_Explode('oh meow?', ' '), ''));
end.

You could also use SCAR's Explode and Implode functions