I often need to parse data within ProcessFlow or Design Studio and thought I'd share some quick tips on parsing text using JavaScript.
If I have a variable called mytext with the value of "David's Blog" and only want to use part of the value I can parse it.
mytext.substring(0,4) would return "David"
Substring returns the text between two points so to get the value substring starts at the 1st position (JavaScript starts with 0, not 1) and ends with the 2nd position.
mytext.substr(0,5) would return "David"
Substr returns the text from the starting point and forward the number of characters specified. If you leave the 2nd position off the substr command it will parse the text to the end point.
mytext.indexOf("Blog") would return 8
The indexOf method searches for your quoted value and returns the starting point of that value within the text.
mytext.length would return 12
The length method returns the number of characters (including spaces) within your text. This method doesn't start with zero so you get the actual number of characters.
You can use these methods together:
mytext.substr(mytext.indexOf("'s"),5) would return "'s Bl"