PDA

View Full Version : Removing comma from string



KeepBotting
07-03-2014, 03:07 PM
Say I've got a function that returns the price of an item, but it does so by reading the source of a webpage.

As a result, it outputs the string including the comma, such as 69,000

What'd be the easiest way to remove the comma?

slacky
07-03-2014, 03:56 PM
... What'd be the easiest way to remove the comma?

var s:String;
begin
s := '123,456';
WriteLn( Replace(s, ',','',[rfReplaceAll]) );
end.

KeepBotting
07-03-2014, 04:41 PM
var s:String;
begin
s := '123,456';
WriteLn( Replace(s, ',','',[rfReplaceAll]) );
end.
facedesk

I had actually seen this used somewhere before but it had completely escaped my memory

Thanks!

/close

Haxz
07-03-2014, 04:55 PM
I remember there's a GetNumber function when I made my merchanter last year, but I can't find the function in Simba anymore :cartman:

KeepBotting
07-03-2014, 09:52 PM
var s:String;
begin
s := '123,456';
WriteLn( Replace(s, ',','',[rfReplaceAll]) );
end.

function getPrice(theItem:string):integer;
var
thePage, thePrice:string;
t:TTimeMarker;
begin
t.start;
thePage := getPage('http://runescape.wikia.com/wiki/Exchange:' + theItem);
thePrice := between('GEPrice">', '</span>', thePage);
replace(thePrice, ',', '', [rfReplaceAll]);
result := strToIntDef(thePrice, -1);
t.pause;
writeDebug('Grabbed price of: ' + theItem + ' (' + thePrice + ') in: ' + intToStr(t.getTime()) + ' ms.');
t.reset;
end;

returns the price with the comma, what am I doing wrong?

Turpinator
07-03-2014, 10:00 PM
function getPrice(theItem:string):integer;
var
thePage, thePrice:string;
t:TTimeMarker;
begin
t.start;
thePage := getPage('http://runescape.wikia.com/wiki/Exchange:' + theItem);
thePrice := between('GEPrice">', '</span>', thePage);
replace(thePrice, ',', '', [rfReplaceAll]);
result := strToIntDef(thePrice, -1);
t.pause;
writeDebug('Grabbed price of: ' + theItem + ' (' + thePrice + ') in: ' + intToStr(t.getTime()) + ' ms.');
t.reset;
end;

returns the price with the comma, what am I doing wrong?
thePrice := replace(thePrice, ',', '', [rfReplaceAll]);

KeepBotting
07-03-2014, 10:06 PM
thePrice := replace(thePrice, ',', '', [rfReplaceAll]);

:duh: thanks!

Olly
07-03-2014, 11:29 PM
function getPrice(theItem:string):integer;
begin
result := strToIntDef(extractFromStr(between('GEPrice">', '</span>', getPage('http://runescape.wikia.com/wiki/Exchange:' + theItem)), Numbers), -1);
end;


I win!

The Mayor
07-04-2014, 12:25 AM
https://villavu.com/forum/showthread.php?t=107485

KeepBotting
07-04-2014, 12:28 AM
https://villavu.com/forum/showthread.php?t=107485
ye i got the 'GEPrice">', '</span>' from yours