Preface:
During project development, when editing input, it is sometimes necessary to judge the legality of the input string. (For example, whether there are spaces), I happened to meet them today, so I will record them by the way ╮( ̄▽ ̄)╭ ~
Example:
String str = "acd dd";
if(str.Index.of(" ")!=-1){
System.out.println("Illegal characters exist!");
}else{
System.out.println("String legal");
}
Similarly, it can also be applied to Android:
String str = "acd&dd";
if(("&")!=-1){
Log.e("TAG","There are illegal characters in the string!");
}else{
Log.e("TAG","String is legal!");
}