Shoutbox

Ripping variables out from a string?? [solved] - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Ripping variables out from a string?? [solved] (/showthread.php?tid=62773)

Ripping variables out from a string?? [solved] by kjfk on 07-07-2006 at 08:58 PM

I dont know what it is called, so i cant really search for it. Might have been asked before, so I am real sorry if so.
Anyways.
I need to rip out variables from a string.
Like if the string is #SomeCommand;Variable1;Variable2 (Example: #DoThat;103;208)
How would I then get the 2 variables into useable variables?
Help Please.


RE: Ripping variables out from a string?? by matty on 07-07-2006 at 09:01 PM

code:
var sTmp = 'this is some text';

sTmp.replace('t', '');

RE: RE: Ripping variables out from a string?? by kjfk on 07-07-2006 at 09:10 PM

quote:
Originally posted by Matty
code:
var sTmp = 'this is some text';

sTmp.replace('t', '');


wont that just replace all t letters in the text with spaces?
im quite new to scripting, trying to learn.. but that is all i can figure that to do.
If you go for my example (#DoThat;103;208), i would want a variable, lets call it var1, to change its value to 103 and another variable, var2, change its value to 208.
I am sorry if i didnt explain good enough :$ .
RE: Ripping variables out from a string?? by Dhaya on 07-07-2006 at 09:14 PM

for example

code:
var strCommand = "#DoThat;130;104";

var arrCommand = strCommand.split(";");
switch (arrCommand[0])
{
    case "#DoThat":
          //use arrCommand[1] to get 130 and arrCommand[2] to get 104
          break;
}



RE: RE: Ripping variables out from a string?? by segosa on 07-07-2006 at 09:15 PM

Matty doesn't seem to have understood your question.

You can use the ".split" method of a string variable to return an array.

For example:

code:
var blah = "#DoThat;103;208";
var arr = blah.split(";");

var var1 = arr[1]; // note it starts at 0, so arr[0] = #DoThat
var var2 = arr[2]; // var2 will be 208


EDIT: Damn you Dhaya. :p
RE: Ripping variables out from a string?? by Dhaya on 07-07-2006 at 09:18 PM

\o/ at least he'll understand better with two examples


RE: Ripping variables out from a string?? by kjfk on 07-07-2006 at 09:18 PM

Thank you very much for helping me ^^


RE: Ripping variables out from a string?? [Solved] by matty on 07-07-2006 at 09:23 PM

Woops help if I read the entire thread :S


RE: Ripping variables out from a string?? [solved] by dramado on 07-08-2006 at 06:43 AM

function DoThat(a,b)
{
return a*b;
}

var blah = "DoThat(332,343)";
var DoneThat = eval(blah);