Extract String in Java | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

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

3rd Jul 2022, 2:11 PM
notstacked
2 Respostas
+ 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]); }
3rd Jul 2022, 2:26 PM
AĶ¢J
AĶ¢J - avatar
+ 1
Thank you so much AĶ¢J
3rd Jul 2022, 8:06 PM
notstacked