commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Baltz, Kenneth" <Kba...@firstam.com>
Subject RE: [Lang] StringUtils.split() with quoted strings
Date Mon, 23 Dec 2002 16:44:09 GMT
I suspect you could do this with regular expressions (java.util.regex.*).
There's a split() method in Pattern that will split a string around pattern
matches, but it looks like this is basically an advanced version of
StringTokenizer.  I think for your needs, you need a pattern along the lines
of /(\b\w+\b)|("[^"]+")/.   If you're not familiar with regex gibberish, I'm
attempting to creating a pattern that matches either of two things.  The
first looks for "word" characters (a-zA-Z) with "word boundaries" on either
side, OR (|), I look for any characters that are surrounded by double
quotes.  

K.C.

> -----Original Message-----
> From: Davor Cengija [mailto:davor.cengija@mail.inet.hr]
> Sent: Sunday, December 22, 2002 2:25 AM
> To: commons-user@jakarta.apache.org
> Subject: [Lang] StringUtils.split() with quoted strings
> 
> 
> Is there a method in StringUtils or some other utility class 
> which splits a 
> string into an array, but taking care of quoted substrings? 
> E.g., a string
> 
> This is "a quoted substring" and some "other text"
> 
> should be split to
> 
> This
> is
> a quoted substring
> and 
> some
> other text
> 
> StreamTokenizer does a good job with a single quote char, but 
> I'd like to 
> have multi-char word and substring separators.
> 
> If not, I might give it a try.
> 
> Cheers,
> Davor
> -- 
> davor.cengija@mail.inet.hr
> 
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:commons-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:commons-user-help@jakarta.apache.org>
> 
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message