Results 1 to 2 of 2

Thread: editing text string for output?

  1. #1
    Join Date
    Aug 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default editing text string for output?

    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?

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    You can use the ".split" function in JS to break up a string like this into its separate parts.

    eg
    Code:
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •