I have a string whose first character is "^". I want to extract the string without this character. For eg : "^coal" should become "coal". Following is the code I wrote, but I don't know why it's not working.
public void RegEx(String s1){
System.out.println(s1.substring(0,1)); //to check if i am ok.
if((s1.substring(0,1)).equals("^")){
Pattern p = Pattern.compile("^");
String[] extracted = p.split(s1);
for(String s: extracted){
System.out.println(s);
}
}
}
s1 = "^coal". Output = "^coal".
s1 = s1.substring(1);inside yourifstatement? For example,"MyString".substring(1);evaluates to"yString"