Reputation: 101
currently I am using String.split("")
like so:
String[] tmp = props.get(i).getFullName().split("\\.");
String name = "";
for(int j = 1; j < tmp.length; j++){
if(j > 1){
name = name + "." + tmp[j];
}
else
name = name + tmp[j];
}
my String is in the format of first.second.third...n-1.n
and all i really need to do is get rid of first.
Upvotes: 3
Views: 610
Reputation: 129489
You can use java.util.regex
and execute a regex instead.
The regex to match first.
is ^[^.]+[.]
String s = "first.second.third...n-1.n";
s.replaceAll('^[^.]+[.]', '');
Upvotes: 4
Reputation: 533750
I would use
String s = "first.second.third...n-1.n";
s = s.substring(s.indexOf('.')+1);
// or
s = s.replaceFirst(".*?\\.", "");
System.out.println(s);
prints
second.third...n-1.n
Upvotes: 8