-4

I am developing a program in which i am getting response from server like"1.user 2.name 3.mobile". I have to how these value in sequence. How do i spilt these value in sequence.

String i = "1.user 2.name 3.mobile";

I want it in pattern

1.user

2.name

3.mobile

Ravi
  • 117
  • 1
  • 8

4 Answers4

0

Try this code

String i = "1.user 2.name 3.mobile";
String split[]=i.split(" ");
String firstValue=split[0];//1.user
String secondValue=split[1];//2.name
String thirdValue=split[2];//3.mobile
Rajakumar
  • 907
  • 1
  • 7
  • 17
0
        String i = "1.user 2.name 3.mobile";
        String[] array = i.split("\\s");
        for (int j = 0; j < array.length; j++) {
            System.out.println(array[j]); \\ will get like 1.user 
            String[] innerArray = array[j].split("\\.");\\if you want name and sequence split through "."
            for (int k = 0; k < innerArray.length; k++) {
                System.out.println(innerArray[k]); will get like \\ 1  , user
            }
        }
Mayur Raval
  • 3,250
  • 6
  • 34
  • 57
0

You can use String.split function

String i = "1.user 2.name 3.mobile";
String[] array = i.split(" ");
for (int j = 0; j < array.length; j++) {
    Log.e("Tag", array[j]);
}
Mahesh Babariya
  • 4,560
  • 6
  • 39
  • 54
0
Tested and working!
        ArrayList<String> alData=new ArrayList<>();
        String i="1.user 2.name 3.email";  
        String[] array = i.split("\\b[0-9].");
        StringBuffer sb = new StringBuffer("");
         for(int j=1;j<array.length;j++)
           {
         //sb.append(j+1+""+array[j]+"\n ");
         alData.add(j+" "+array[j]);
         System.out.println(j+" "+array[j]);     
     }
       for(int k=0;k<alData.size();k++)
      {
      TextView tv=new TextView(mContext);
      tv.setText(alData.get(k));
      linearLayout.addView(tv);//you have to create a static linearLayout in your xml 
      }
Rushi Ayyappa
  • 2,708
  • 2
  • 16
  • 32