-4

I am working on android application. I am getting the String value from webservice extension i want to split 4 from the string by using index .pls tell me how can do this

String version = "1.4.2";

Sanawaj
  • 384
  • 1
  • 6
user2914699
  • 265
  • 1
  • 3
  • 7

4 Answers4

1

Try this..

String version = "1.4.2";
Log.v("value ",""+version.split("\\.")[1]);

For more information Refer Link1,Link2

Community
  • 1
  • 1
Hariharan
  • 24,741
  • 6
  • 50
  • 54
1

can you try this :

 String[] items = "1.4.2".split("\\.");
 String version = items[1].toString();
CompEng
  • 7,161
  • 16
  • 68
  • 122
0

have all the sub-part of your string using

String[] strs = version.split("\.");

now if you want 4 from (1.4.2), do following:

String mMiddle  = strs[1]; // it will give 4 as a string in mMiddle

if you want every sub-part:

String mStart = strs[0]; //returns 1
String mMiddle = strs[1]; //returns 4
String mLast = strs[2]; //returns 2
Jigar
  • 791
  • 11
  • 21
0

Try this code:

String version = "1.4.2";
String arr[]=version.split("\\.");
String value=arr[1].toString();
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);

thank you.

Balder
  • 8,623
  • 4
  • 39
  • 61
Sethu
  • 430
  • 2
  • 13