This question already has answers here:
How do I split a string in Java?
(39 answers)
Closed 9 years ago.
i want to read this string
String "abc;def;ghi;jklm;nopqr"
i want to get these diffrent diffrent
string a = abc;
string b = def;
string c = ghi;
string f = nopqr;`
how i read this , plz help me,
You can use the split method:
String[] tokens = str.split(";")
for example:
String myString = "abc;def;ghi;jklm;nopqr";
String[] tokens = myString.split(";")
//tokens[0]="abc"
//tokens[1]="def"
//...
Try this:
String string = "aaa;bbb";
String[] parts = string.split(";");
String part1 = parts[0]; //aaa
String part2 = parts[1];//bbb
Related
This question already exists:
converting string to arraylist in java [duplicate]
Closed 2 years ago.
Here is my string getting from json response:
daysOfDelivery = getIntent().getStringExtra("DaysOfDelivery");
in daysOfDelivery i have a String "[1,1,1,1,1,1,1]"
using this string i want to show days of week from sunday to monday
UPDATED
List<String> weekDayslist = new ArrayList<String>();
String availabilityDays = "";
String frequency;
frequency = getIntent().getStringExtra("Frequency");
if (frequency != null) {
availabilityDays = getIntent().getStringExtra("DaysOfDelivery");
}
if (!availabilityDays.isEmpty()) {
availabilityDays = availabilityDays.replaceAll("[\(\)\[\]\\{\\}]", "");
for (String field : availabilityDays.split(",")
)
weekDayslist.add(field);
}
I have Two EditText(id=et_tnum,et_pass). I Received a String like 12345,mari#123 inside EditText1(et_tnum) . I want to Split them by Comma and After Comma i should Receive Remainder string into EditText2(et_pass). Here 12345,mari#123 is Account Number & Password Respectively.
String[] strSplit = YourString.split(",");
String str1 = strSplit[0];
String str2 = strSplit[1];
EditText1.setText(str1);
EditText2.setText(str2);
String CurrentString = "12345,mari#123";
String[] separated = CurrentString.split(",");
//If this Doesn't work please try as below
//String[] separated = CurrentString.split("\\,");
separated[0]; // this will contain "12345"
separated[1]; // this will contain "mari#123"
There are other ways to do it. For instance, you can use the StringTokenizer class (from java.util):
StringTokenizer tokens = new StringTokenizer(CurrentString, ",");
String first = tokens.nextToken();// this will contain "12345"
String second = tokens.nextToken();// this will contain "mari#123"
// in the case above I assumed the string has always that syntax (foo: bar)
// but you may want to check if there are tokens or not using the hasMoreTokens method
This answer is from this post
You can use
String[] strArr = yourString.split("\\,");
et_tnum.setText(strArr[0]);
et_pass.setText(strArr[1]);
Try
String[] data = str.split(",");
accountNumber = data[0];
password = data[1];
This question already has answers here:
How do I split a string in Java?
(39 answers)
Closed 7 years ago.
how do i split the string on url link
StringTokenizer st = new StringTokenizer(linkHref, ".ashx?JobID=");;
String community = st.nextToken();
System.out.println(community );
url link below
http://example.com/GetJob.ashx?JobID=19358502&JobTitle=Factory%20Workers%20in%20Oldham%20-%20Immediate%20Start%20Now&rad=20&rad_units=miles&pp=25&sort=rv.dt.di&vw=b&re=134&setype=2&tjt=factory&where=oldham&pg=1&avsdm=2015-09-10T05%3a54%3a00-05%3a00
String s = "http://example.com/GetJob.ashx?JobID=19358502&JobTitle=Factory%20Workers%20in%20Oldham%20-%20Immediate%20Start%20Now&rad=20&rad_units=miles&pp=25&sort=rv.dt.di&vw=b&re=134&setype=2&tjt=factory&where=oldham&pg=1&avsdm=2015-09-10T05%3a54%3a00-05%3a00";
s = s.substring(s.indexOf("JobID=") + 6);
s = s.substring(0, s.indexOf("&JobTitle"));
System.out.println(s);
In my Android app I have a string which value is always from type yo_2014_rojo.
I need to split the string in three parts: part1 ="yo" part2="2014" and part3="rojo".
I am trying to do it as follows:
String s[] = dato_seleccionado.split("_");
String s1 = s[0];
String s2 = s[1];
String s3 = s[2];
but the app crashes with an exception: ArrayIndexOutOfBoundsException.
Any help is welcome.
Try this...
String str = "yo_2014_rojo";
StringTokenizer token = new StringTokenizer(str , "_");
String part1 = token.nextToken(); //yo
String part2 = token.nextToken(); //2014
String part3 = token.nextToken(); //rojo
stringname.split() takes Perl regex as an argument.
Try escaping the underscore, like this:
String[] spliced = dato_seleccionado.split("\\_");
Try doing it like this:
String[] spliced = dato_seleccionado.split("_");
System.out.println(Arrays.toString(spliced)); // check if you have the correct output
String s1 = spliced[0];
String s2 = spliced[1];
String s3 = spliced[2];
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";
Try this..
String version = "1.4.2";
Log.v("value ",""+version.split("\\.")[1]);
For more information Refer Link1,Link2
can you try this :
String[] items = "1.4.2".split("\\.");
String version = items[1].toString();
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
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.