What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Ripping variables out from a string?? [solved]

Ripping variables out from a string?? [solved]
Author: Message:
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. Ripping variables out from a string?? [solved]
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.

This post was edited on 07-07-2006 at 09:57 PM by kjfk.
07-07-2006 08:58 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Ripping variables out from a string??
code:
var sTmp = 'this is some text';

sTmp.replace('t', '');
07-07-2006 09:01 PM
Profile E-Mail PM Find Quote Report
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. RE: RE: Ripping variables out from a string??
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 :$ .

This post was edited on 07-07-2006 at 09:12 PM by kjfk.
07-07-2006 09:10 PM
Profile E-Mail PM Find Quote Report
Dhaya
Junior Member
**

Avatar
lala~

Posts: 25
Reputation: 4
38 / Male / –
Joined: Jul 2006
RE: Ripping variables out from a string??
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;
}



This post was edited on 07-07-2006 at 09:15 PM by Dhaya.
Godamn JScript ! I HATE you ! ... but I love you so much <3
07-07-2006 09:14 PM
Profile PM Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: RE: Ripping variables out from a string??
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

This post was edited on 07-07-2006 at 09:16 PM by segosa.
The previous sentence is false. The following sentence is true.
07-07-2006 09:15 PM
Profile PM Find Quote Report
Dhaya
Junior Member
**

Avatar
lala~

Posts: 25
Reputation: 4
38 / Male / –
Joined: Jul 2006
RE: Ripping variables out from a string??
\o/ at least he'll understand better with two examples
Godamn JScript ! I HATE you ! ... but I love you so much <3
07-07-2006 09:18 PM
Profile PM Find Quote Report
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. RE: Ripping variables out from a string??
Thank you very much for helping me ^^
07-07-2006 09:18 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Ripping variables out from a string?? [Solved]
Woops help if I read the entire thread :S
07-07-2006 09:23 PM
Profile E-Mail PM Find Quote Report
dramado
New Member
*


Posts: 11
Joined: Jun 2006
RE: Ripping variables out from a string?? [solved]
function DoThat(a,b)
{
return a*b;
}

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

This post was edited on 07-08-2006 at 06:44 AM by dramado.
07-08-2006 06:43 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On