Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Spliting String on space

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?

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

View solution in original post

2 Replies
Anonymous
Not applicable
Author

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

Anonymous
Not applicable
Author

Thanx, it actually solved it ^^