You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ha ryon <ha...@gmail.com> on 2004/11/19 11:30:28 UTC

[lang] Additions to StringUtils ?

- I would like to be able to split a string using a String (more than
one character long) separator.
split("John:Arthur::Renaud:Sylvan::me:you", "::") ->[ "John;Arthur",
"Renaud:Sylvan", "me:you" ]

- I would like to fastly join and quote at the same time :
join(["me", "you", "them"], "|", "<", ">") -> "<me>|<you>|<them>"
basically, I would usually use it to turn an array into some
javascript or sql list :
join( ["me", "you", "them"], ", ", "'", "'") -> "'me', 'you', 'them'" 
and then "select * from guys where name in (" + ... + ")". Idem with
generating some javascript to a jsp.

- then split such a quoted string back to an array.
split("'me', 'you', 'them'", ", ", "'", "'") -> ["me", "you", "them"]


(I know I can do all of this with regexp, or a bit of work, but the
question is always can i do it with one line :) --- ** lazy !! **)

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [lang] Additions to StringUtils ?

Posted by Emmanouil Batsis <Em...@eurodyn.com>.
Ha ryon wrote:

>- I would like to be able to split a string using a String (more than
>one character long) separator.
>split(, "::") ->[ "John;Arthur",
>"Renaud:Sylvan", "me:you" ]
>  
>
I think this is available in all 1.4+ JREs:

"John:Arthur::Renaud:Sylvan::me:you".split("::");

see

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org