function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
timarptimarp 

String split help

This is probably an easy one, but I am kind of lost when it comes to regular expressions

 

So this is the string I have

 

0.0|||||||1.0|Arizona;California;||||||

 

The | is a "|" sign.

 

I would like to be able to split the string on that character. I was reading about the String.split() method, however some concrete example would be appreciated. Thanks!

Madhan Raja MMadhan Raja M

Try this out:

 

String myString='0.0|||||||1.0|Arizona;California;||||||';
List<string> state = new List<string>();
for(String s: myString.Split('&#124;')){
     state.add(s);
}
System.debug(state);

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Madhan Raja M

timarptimarp

Madhan,

 

I tried this myString.Split('\|') and it worked. I simply had to escape the '|' sign. Thank you for pointing me in the right direction