SRL Archive - RS3 Help

Removing comma from string


KeepBotting

2014-07-03 11:07:12

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

2014-07-03 11:56:16

From: KeepBotting
… What'd be the easiest way to remove the comma?


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

KeepBotting

2014-07-03 12:41:43

From: slacky

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

2014-07-03 12:55:58

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

2014-07-03 17:52:45

From: slacky

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

2014-07-03 18:00:34

From: KeepBotting
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

2014-07-03 18:06:00

From: Turpinator
thePrice := replace(thePrice, ',', '', [rfReplaceAll]);


:duh: thanks!

Olly

2014-07-03 19:29:44

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

2014-07-03 20:25:50

https://villavu.com/forum/showthread.php?t=107485

KeepBotting

2014-07-03 20:28:44

From: The Mayor
https://villavu.com/forum/showthread.php?t=107485

ye i got the 'GEPrice">', '</span>' from yours