+ 5
How can we cut a string ? In Java
String a = "SPcoder" how to get just coder from variable 'a'?
5 Answers
+ 6
You can use substring:
public String substring(int startIndex);
public String substring(int startIndex, int endIndex);
+ 5
Thanks aelbler
+ 3
Assumuning you dont want to hard code it, useâ>
a = substring(a.indexOf(âcoderâ));
The substring returns the string, starting from the index position of your parameter, and the indexOf method returns the index of the start of the first occurunce of the String segment inside the string. returning a -1 if the String segment does not exist
+ 3
use StringBuffer class
+ 2
Vivan Shah But that won't work all the time. substring gets you to the first character of the substring, but the way you do it, there is no end to the substring.