I have a following string
books/eh/grayL88/WilliamsMC88:::M. Howard Williams::P. A. Massey::Jim A. Crammond:::Benchmarking Prolog for Database Applications.
How should i use or in other words what to use so that at last i may get
M. Howard Williams -- Benchmarking Prolog for Database Applications.
P. A. Massey -- Benchmarking Prolog for Database Applications.
Jim A. Crammond -- Benchmarking Prolog for Database Applications.
Thanks
:::
. This will give you an array of length 3. You would be interested in the 2nd
and the 3rd
element of your array.2nd element
of your array on ::
. This will give you an array containing each name
.Iterate over the 2nd array
and print each name with the 3rd element
of your first array.
String str = "books/eh/grayL88/WilliamsMC88:::M. Howard Williams::" +
"P. A. Massey::Jim A. Crammond:::Benchmarking Prolog for " +
"Database Applications.";
String[] arr = str.split(":::");
String[] innerArr = arr[1].split("::");
for (String name: innerArr) {
System.out.println(name + " -- " + arr[2]);
}
OUTPUT: -
M. Howard Williams -- Benchmarking Prolog for Database Applications.
P. A. Massey -- Benchmarking Prolog for Database Applications.
Jim A.Crammond -- Benchmarking Prolog for Database Applications.
Or, you can split on :::?
. This will split on ::
or :::
, that will get each individual elements in your first array only (Will work only for 3
names. For more, you should better use the first one)
String[] arr = str.split(":::?");
System.out.println(arr[1] + " - " + arr[4]);
System.out.println(arr[2] + " - " + arr[4]);
System.out.println(arr[3] + " - " + arr[4]);
OUTPUT: -
M. Howard Williams - Benchmarking Prolog for Database Applications.
P. A. Massey - Benchmarking Prolog for Database Applications.
Jim A. Crammond - Benchmarking Prolog for Database Applications.
You could try something like this:
String s = "books/eh/grayL88/WilliamsMC88:::M. Howard Williams::P. A. Massey::Jim A. Crammond:::Benchmarking Prolog for Database Applications.";
String split[] = s.split(":::");
String end = split[split.length - 1];
String[] names = split[1].split("::");
for (String name : names)
System.out.println(name + " -- " + end);
Output:
M. Howard Williams -- Benchmarking Prolog for Database Applications.
P. A. Massey -- Benchmarking Prolog for Database Applications.
Jim A. Crammond -- Benchmarking Prolog for Database Applications.
Try something along the lines of: (Pseudo code...)
myString.remove("(.*/)+[^:]*:{3}");
lastString = myString.split(":::").takeLast();
array names = myString.split("([^:]*)+");
result = "";
for (i=0;i<name.size();result+=names[i++]+" -- "+lastString+"\n");
// do whatever with "result"...
No freebies, not ever...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With