You need to sign in to do that
Don't have an account?

String.Split doesn't work with vertical bar character "|" [and other regex characters]
This is pretty strange. When spliting a string using a vertical bar, it appears to split between numerical characters also.
String.Split actually uses regular expressions to perform the split. So even though I'm using the same character, it is interpreted differently. This will be the case for other regeular expression characters also.
So the solution to this issue is to use two delimiters, one to join and one to split:
string DelJoin = '|';
string DelSplit = '\\|';
//Original test code:
public static testmethod void SplitTest() { string delim = '|'; string ToSplit = '-9.99999999911101E14' + delim + '1000011'; List<string> SplitValues = ToSplit.split(delim); System.Debug('@@@SplitTest:' + SplitValues); integer sz = SplitValues.Size(); System.AssertEquals(2, sz); //This fails with a value of 29 integer Pointer = integer.valueOf(SplitValues[sz-1]); System.Debug('@@@SplitTest:' + Pointer); System.AssertEquals(1000011, Pointer); }
Yes, that's how I came to the conclusion that is was using RegEx in the split. That feature will come in handy some day.
I've determined, for this and going forward, I will use an unprintable ASCII character,
The 1F (hex) character is specificall for "Unit Separater". This has no special meaning in regular expressions.
All Answers
This appears to either be something VERY unique about String.split() and the pipe character |
Will look into it.
I found a blog entry which explains it pretty well in Java. In the case of String.split(), Apex follows the same rules as Java.
http://www.jamesnetherton.com/blog/2010/10/13/java-string-split-with-pipe-characters/
Hope this helps!
Just to add to spraetz's reply, you may wish to read the entire String.split() entry from the Java documentation, because it is literally identical behavior (in fact, the documentation for this function actually has a link to the corresponding Java documentation that covers this feature).
Yes, that's how I came to the conclusion that is was using RegEx in the split. That feature will come in handy some day.
I've determined, for this and going forward, I will use an unprintable ASCII character,
The 1F (hex) character is specificall for "Unit Separater". This has no special meaning in regular expressions.