|
Re: using the trim() on Strings [message #717103 is a reply to message #717001] |
Fri, 19 August 2011 10:20 |
Louis Rose Messages: 440 Registered: July 2009 Location: York, United Kingdom |
Senior Member |
|
|
vrm wrote on Thu, 18 August 2011 23:42On the EOL String primitive type , the split() does not seem to work with a "." as the delimiter.The same is the case with replace().
For instance :
var str:String = "hello.world";
var seq:Sequence;
seq = str.split('.');
From the above code,I expect the sequence to hold two objects,but that is not the case.
What am I missing here ?
Hi vrm,
The short answer: to match a full stop with split or replace, use the following argument: "\\."
var str:String = "hello.world";
var seq:Sequence;
seq = str.split('\\.');
The long answer: the parameter to split() (and to replace()) is a Java regular expression. The full stop has special significance in regular expressions, so it needs to be escaped with a backslash, and we get: "\." However, the backslash is the Java escape character in a string literal, so we must escape the backslash, and we get: "\\."
Cheers,
Louis.
|
|
|
Powered by
FUDForum. Page generated in 0.03258 seconds