String.split()

I

Ike

Can anyone please tell me why the following:


String rxsl="1}{2}{3}{4}{5}{6}{7}{9}{10}{12}{13}{14}{15}{17";
String rsxla[] = rxsl.split("^.*\\}\\{.*$");

produces rxsla[0]="1}{2}{3}{4}{5}{6}{7}{9}{10}{12}{13}{14}{15}{17";

???

and not
rxsla[0]="1";
rxsla[1]="2";
....
rxsla[13]="17";

clearly I have something (simple and stupid) wrong -- but for the life of
me, cannot find it here. Thanks, Ike
 
S

Starshine Moonbeam

Ike said:
Can anyone please tell me why the following:


String rxsl="1}{2}{3}{4}{5}{6}{7}{9}{10}{12}{13}{14}{15}{17";
String rsxla[] = rxsl.split("^.*\\}\\{.*$");

produces rxsla[0]="1}{2}{3}{4}{5}{6}{7}{9}{10}{12}{13}{14}{15}{17";

???

and not
rxsla[0]="1";
rxsla[1]="2";
...
rxsla[13]="17";

clearly I have something (simple and stupid) wrong -- but for the life of
me, cannot find it here.

String[] something = new String[var]

if var = 2

something[0] is set to "null"
something[1] is set to "null"
something[2] is set to "null"

You could just assign them normally or you can declare the array values
right off the bat

String[] something = {"blue", "red", "orange"};
 
S

Scott Lopez

This worked better for me:

String rxsl="1}{2}{3}{4}{5}{6}{7}{9}{10}{12}{13}{14}{15}{16";
//String rsxla[] = rxsl.split("^.*\\}\\{.*$");
String rsxla[] = rxsl.split("\\}\\{");

int size = rsxla.length;

for(int i = 0; i < size; ++i)
{
System.out.println(rsxla);
}


results:
1
2
3
4
5
6
7
9
10
12
13
14
15
16
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,251
Members
46,851
Latest member
CristineKo

Latest Threads

Top