find a value in a string

Results 1 to 2 of 2

Thread: find a value in a string

  1. #1
    mojo jojo Guest

    Default find a value in a string

    i have a string delimited by ~<BR><BR>i would like to search for a variable and then return the next two values in the string delimited by *<BR><BR>example<BR><BR>~*123*876*765~*345*456*234 ~*....<BR><BR>so if i search for ~*345 it should find it and return 456 and 234 in two diff variables<BR><BR>the items between the * may be less than 3 or more than 3.<BR><BR>Please help me with this<BR><BR>I have to do this in client side Java Script only<BR><BR>Thanks in advance

  2. #2
    Join Date
    Dec 1969

    Default RE: find a value in a string

    &#060;SCRIPT LANGUAGE=JavaScript&#062;<BR>&#039 assumptions:<BR>findIn = "...*123*876*765~*345*456*234~*...."<BR>findSt art = "345"<BR><BR>&#039 code:<BR>&#039 surround findStart with *...* so no false matches!<BR>startAt = findIn.indexOf( "*"+findStart+"*" )<BR>&#039 find the three *&#039s that follow that:<BR>star1 = findIn.indexOf( "*", startAt+1 )<BR>star2 = findIn.indexOf( "*", star1+1 )<BR>star3 = findIn.indexOf( "*", star2+1 )<BR>&#039 now get the substrings:<BR>val1 = findIn.substring( star1+1, star2 )<BR>val2 = findIn.substring( star2+1, star3 )<BR>%&#062;<BR><BR>I might be off by +1 or -1 on some of those, so adjust if needed.<BR><BR>

Posting Permissions

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