Forum Moderators: open
I'm not going to write the whole script for you, but here's how I see the logic for it:
1. assign a variable name to the string - s
2. initialize a loop counter variable - i
3. set up an empty array to hold your extracted variables
----- BEGIN LOOP -----
4. find position of the first "special" character - m
5. ESCAPE LOOP if "special" character is not found
6. find position of the "stop" character - n
7. ESCAPE LOOP if "stop" character is not found
8. define a new variable to be s.substring(m+1,n-1) - v
9. assign "v" to be a new array element (use the loop counter)
10. reassign the value of "s" to be s.substring(n+1,s.length)
11. increment the loop counter
----- LOOP BACK -----
That way you would create an array where each element was one of the variables you wanted to extract from the string.
I'm still learning Javascript
Aren't we all ;)
I've never had the luxury of a solid course of study, just the pressure of immediate needs, handled through Google searches and an O'Reilly book or two. We've got members here who know a lot more than I do, and who use javascript a lot more than I do.
Glad the logic helps out.
e.g.
var my_string = "hello this is a string";
var first = my_string.indexOf("o");
// Now "first" is set to 4, the position of the first "o" in the string.
// If it did not find the "o", it would return -1.
Then form a substring of my_string from first to my_string.length, and use indexOf() on the new string to find the occurance of the next character you are looking for. Then use substring to extract.
Shawn
[added:] OOPS, I just realised this is not really an 'alternative', just more detail on how to do the steps 4 and 6 in Ted's post. However, another built-in that may be useful is:
string_name.split(separator char, limit)'