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);
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);
}
This question already has answers here:
Split string at commas
(4 answers)
Closed 7 years ago.
I am getting the lat-long from the current location now how can i split the only lat long values from a given string :-
"lat/lng: (23.0326542,72.5279697)"? i want to get only "23.0326542,72.5279697".
Try this:
String line = "lat/lng: (23.0326542,72.5279697)";
String[] array = line.split(",");
for (int i = 0; i < array.length; i++) {
Pattern pattern = Pattern.compile("(\\d+\\.\\d+)|(\\d+)");
Matcher m = pattern.matcher(array[i]);
if (m.find()) {
System.out.println(m.group(1));
}
}
It looks like you should be taking the substring of this string, from the beginning of the value you need, to the length of the string.
This question already has answers here:
How to parse JSON in Java
(36 answers)
Closed 8 years ago.
I have,
[{"GroupPosition":0,"ChildPosition":0},{"GroupPosition":0,"ChildPosition":1},{"GroupPosition":1,"ChildPosition":0}]
How do I split them into:
GroupPosition:
[0,0,1] or {0,0,1}
ChildPosition:
[0,0,0] or {0,0,0}
Your input is in json format. Consider my code is sample.
private static ArrayList<String> array_1 = new ArrayList<String>();;
String json = [{"GroupPosition":0,"ChildPosition":0},{"GroupPosition":0,"ChildPosition":1},{"GroupPosition":1,"ChildPosition":0}];
JSONArray leagues = new JSONArray(json);
for (int i = 0; i < leagues.length(); i++) {
JSONObject obj = leagues.getJSONObject(i);
array_1.add(obj.getString("GroupPosition"));
}
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.
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