You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by TIMMERMAN Craig <Cr...@alcatel-lucent.com> on 2008/01/24 17:33:29 UTC
split a string on newline
Hello,
I have been searching for a solution and haven't seen anything yet, here
is the problem:
I have a string that contains values separated by new line characters.
Is there any way to split the string into an array? I've tried
#set( $aStringArray = $Property1.split("\n") )
but it doesn't seem to understand the new line character. Is there any
way to do this?
Thanks.
Re: split a string on newline
Posted by Nathan Bubna <nb...@gmail.com>.
Yeah, VTL isn't the same as java with regard to string escape
sequences. Have you tried:
#set( $aStringArray = $Property1.split("
") )
On Jan 24, 2008 8:33 AM, TIMMERMAN Craig
<Cr...@alcatel-lucent.com> wrote:
> Hello,
>
> I have been searching for a solution and haven't seen anything yet, here
> is the problem:
>
> I have a string that contains values separated by new line characters.
> Is there any way to split the string into an array? I've tried
>
> #set( $aStringArray = $Property1.split("\n") )
>
> but it doesn't seem to understand the new line character. Is there any
> way to do this?
>
> Thanks.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: split a string on newline
Posted by XtraByte <va...@gmail.com>.
By converting it into UTF8 String, you can do as follows
System.out.println("Query:\n" + query);
Vector<String> queries = new Vector();
try {
query = URLEncoder.encode(query, "UTF8");
System.out.println("Encoded: " + query);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(ResultSetTable.class.getName()).log(Level.SEVERE, null,
ex);
}
String[] list = query.split("%3B%0D%0A");
System.out.println(list.length + " queries found in the input");
for (int i = 0; i < list.length; i++) {
String q = list[i];
System.out.println("query: " + q);
try {
q = URLDecoder.decode(q, "UTF8");
System.out.println("Decoded: " + q);
if(q!= null){
q = q.trim();
}
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(ResultSetTable.class.getName()).log(Level.SEVERE, null,
ex);
}
queries.add(q);
=========================
TIMMERMAN Craig wrote:
>
> Hello,
>
> I have been searching for a solution and haven't seen anything yet, here
> is the problem:
>
> I have a string that contains values separated by new line characters.
> Is there any way to split the string into an array? I've tried
>
> #set( $aStringArray = $Property1.split("\n") )
>
> but it doesn't seem to understand the new line character. Is there any
> way to do this?
>
> Thanks.
>
>
>
--
View this message in context: http://www.nabble.com/split-a-string-on-newline-tp15069810p22949728.html
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org