Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite0
Extract String in Java
I want to extract only certain portion of String followed by = sign The string is “[AlbumId=1, CategoryId=1, albumTitle=DJ NYK, hirePrice=20, noofCD=5, status=Available]” From here I want to extract "1","1","DJ NYK","20",5,"Available" .I have tried with split() but I cannot extract properly .Will be highly grateful if I receive any help
2 Réponses
+ 4
notstacked
You can first split string on comma (,) then after splitting string will be convert in array of string.
Now use for loop and split each string of that new array with equal (=)
Here is an example:
String str = "1=2, 3=4, 5=6";
String [] arr = str.split(", ");
for (String s : arr) {
String[] a = s.split("=");
System.out.println(a[1]);
}
+ 1
Thank you so much A͢J