SRL Archive - Other Scripts

String Question


benjaa

2008-10-18 07:08:34

Hello Forumers,

My question for you today is;

How can I change my existing string 'Health: 90/100' into '90'?

I've had an idea that you could take everything before the '/', then change the string to a number (thus removing 'health: '), but I'm not sure what the first half of the command is.

Rep awarded as always.

Thanks in advance,

mixster

2008-10-18 08:25:33

hp := StrToIntDef(Between(':', '/', 'Health: 90/100'), 0);

StrToIntDef is just like StrToInt, except it takes in an Integer as well, which it will return if it can't produce a valid integer from the conversion, ie StrToIntDef('moo', 10) will return 10 as moo can't be an integer. It primarily just stops it crashing.
Between takes 3 strings: 1st string is where you want to start copying from and the 2nd string is where you want to end copying. The 3rd string is the string where it is to find the stuff to copy.
I hope that works, though I must say that you should post scripting questions in the "Scripting Help" section in future rather than here, as this is meant for posting non-RS related scripts, rather than for help :)

Freddy1990

2008-10-18 14:36:02

Don't double post and post in the wrong section. Locked.