http://blog.csdn.net/pipisorry/article/details/43303145
Java judgment string contains a character segment
1. Using the IndexOf () method
String str = "1234567";
if (Str.indexof ("23")! =-1) {
System.out.println ("contains this string");
}
public void Test1 () {
String string = "Good morning Everyone";
String sub = "Morning";
int a = String.IndexOf (sub);
if (a >= 0) {
System.out.println ("Morning position in the string:" + a);
String SS1 = string.substring (0, A + sub.length ());
String SS2 = string.substring (A + sub.length (), String.Length ());
SYSTEM.OUT.PRINTLN ("The result you need is:" + SS1);
System.out.println ("Deleted characters are:" + SS2);
} else {
System.out.println ("does not exist");
}
}
2. Using the Repalce () method
public class Test {public static void Main (string[] args) { String S1 = "abc"; String s2 = "1111abcdefe"; if (S2.contains (S1)) { System.out.println ("S2 contains S1"); Remove S1 s2 = s2.replace (s2.substring (S2.indexof (S1), S2.length ()), ""); SYSTEM.OUT.PRINTLN (s2); } else{ System.out.println ("S2 does not contain S1");}}}
from:http://blog.csdn.net/pipisorry/article/details/43303145
Ref
Java string processing