Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » using the trim() on Strings(using the trim() on Strings with "." as delimiter)
using the trim() on Strings [message #717001] Fri, 19 August 2011 03:42 Go to next message
vrm  is currently offline vrm Friend
Messages: 31
Registered: June 2011
Member
On 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 ?
Re: using the trim() on Strings [message #717103 is a reply to message #717001] Fri, 19 August 2011 10:20 Go to previous message
Louis Rose is currently offline Louis RoseFriend
Messages: 440
Registered: July 2009
Location: York, United Kingdom
Senior Member
vrm wrote on Thu, 18 August 2011 23:42
On 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.
Previous Topic:[EVL] replace automated messages with mine
Next Topic:[Flock] error while executing migration strategy distributed via plugin
Goto Forum:
  


Current Time: Mon Dec 22 19:41:49 GMT 2014

Powered by FUDForum. Page generated in 0.14242 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software