-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
  • 28,756
  • 7
  • 51
  • 55
1

can you try this :

 String[] items = "1.4.2".split("\\.");
 String version = items[1].toString();
Ersin Gülbahar
  • 6,713
  • 15
  • 60
  • 114
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
  • 10
  • 20
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,417
  • 4
  • 37
  • 60
Sethu
  • 430
  • 2
  • 13