Determine if string starts with letters A through I
问题 I've got a simple java assignment. I need to determine if a string starts with the letter A through I. I know i have to use string.startsWith(); but I don't want to write, if(string.startsWith("a")); all the way to I, it seems in efficient. Should I be using a loop of some sort? 回答1: You don't need regular expressions for this. Try this, assuming you want uppercase only: char c = string.charAt(0); if (c >= 'A' && c <= 'I') { ... } If you do want a regex solution however, you can use this