APD Toronto
asked on
String Manipulation with JS
Hi Experts,
Can anyone tell me how to search for end extract string paths of a string using JavaScript?
For example, say you have a string like ABC{23}, I want to extract this as "ABC" as str1 and "23" as str2. Here is my pseudo-code for this:
pos = strpos(str0, "{")
str1 = substr(str0, 0, pos) //get everything until "{"
str0 = substr(str0, pos+1) //get everything after "{"
pos = strpos(str0, "}"
str2 = substr(str0, 0, pos) //get everything until "}"
Any help will be appreciated.
Can anyone tell me how to search for end extract string paths of a string using JavaScript?
For example, say you have a string like ABC{23}, I want to extract this as "ABC" as str1 and "23" as str2. Here is my pseudo-code for this:
pos = strpos(str0, "{")
str1 = substr(str0, 0, pos) //get everything until "{"
str0 = substr(str0, pos+1) //get everything after "{"
pos = strpos(str0, "}"
str2 = substr(str0, 0, pos) //get everything until "}"
Any help will be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No points please, as I not not posting answer to your question.
But bookmark this link about split function. Really nice reference and examples
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
But bookmark this link about split function. Really nice reference and examples
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
ASKER
Thanks.
and an alternative way would be using Javascript and regular expressions:
Open in new window
http://jsfiddle.net/EE_RainerJ/dtsja7bd/HTH
Rainer