In java let say I having String s="AB.ABC.PQR.No.S502\2022-2023" from this string s I need only "S502" so what will be the code or method to get the specific part of the String .
CodePudding user response:
You can use substring method documentation so if you want to extract the string between the last point and '' character you should try those methods: With str.substring you can extrac the str between 2 params you expecify, also with str.lastIndexOf() you can code something like this:
String s="AB.ABC.PQR.No.S502\2022-2023";
System.out.println(s.substring(s.lastIndexOf(".") 1, 18));
I use 18 directly because "" character can cause conflicts, you can replace it with s.lastIndexOf('\');
Output:
.S502\
CodePudding user response:
String s1="AB.ABC.PQR.No.S502\2022-2023"; System.out.println(s1.substring(14,18));