Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, if someone could please help me, i'm trying to split a string like this:
String s1=input_row.m_lines;
int pos=s1.indexOf(":");
context.Line=s1.substring(0,pos) ;
context.Mask=s1.substring(pos+1) ;
String str = s1.substring(0,pos) ;
String[] splited = str.split("\\s+");
//System.out.println(context.Line);
System.out.println(splited);
and it gives me this:
[statistics] connecting to socket on port 3496
[statistics] connected
[Ljava.lang.String;@2669b199
[Ljava.lang.String;@2344fc66
[Ljava.lang.String;@458ad742
[statistics] disconnected
The output of System.out.println(context.Line) without the split function is:
Name
Surname
Email
i want to split all and store each in different variables, anyways to do so?
Hi,
please note that you do not print out the content of your Array after split.
<< System.out.println(splited);
To print out a value stored in the array you would acces it like : System.out.println(splited[0]);
See also following snippet and try it out :
String s1="Hello my dear I do have something to say I hope you gonna like it";
String[] splited = s1.split("\\s+");
//System.out.println(context.Line);
System.out.println(splited);
for(String w:splited){
System.out.println(w);
}
The output will be :
[Ljava.lang.String;@7852e922
Hello
my
dear
I
do
have
something
to
say
I
hope
you
gonna
like
it
----------------------------
I hope it helps
BR B_p
Hi,
please note that you do not print out the content of your Array after split.
<< System.out.println(splited);
To print out a value stored in the array you would acces it like : System.out.println(splited[0]);
See also following snippet and try it out :
String s1="Hello my dear I do have something to say I hope you gonna like it";
String[] splited = s1.split("\\s+");
//System.out.println(context.Line);
System.out.println(splited);
for(String w:splited){
System.out.println(w);
}
The output will be :
[Ljava.lang.String;@7852e922
Hello
my
dear
I
do
have
something
to
say
I
hope
you
gonna
like
it
----------------------------
I hope it helps
BR B_p
Thanx, it actually solved it ^^