PDA

View Full Version : editing text string for output?



sethwb
04-22-2009, 04:03 PM
Hi:

Here is the string:

Jim Peterson 21 | Ed N 31 | Mary Joe 24 | jennifer baley 22

I am trying to grab all the text other than the "|" and output that to a text field (or global variable)..

How can we do this? I can't seem to find any scripts that show me exactly how to delete all those "|"...

is there a way to put "jim peterson 21" and "ed n 31", etc.. into their own variables?

forum_amnesiac
04-22-2009, 04:44 PM
You can use the ".split" function in JS to break up a string like this into its separate parts.

eg


function strsplit{
var mystring="Jim Peterson 21 | Ed N 31 | Mary Joe 24 | jennifer baley 22";
arrayofparts=mystring.split("|");
part1=arrayofparts[0];
part2=arrayofparts[1];
part3=arrayofparts[0];
part4=arrayofparts[1];
}

Then you are free to do what you want with the separate variables