This content has been marked as final. Show 5 replies
blazingwolf7 wrote:There isn't a built in function like String.firstChar() that would give you the first character of any String. You can easily make one though.
I search through all the String and char method but it doesn't seems to be any method to do this.
Is there anyway I can detect the first char in a String
Is there a method that allows me to detect H directly?
I guess you mean the first character of a particular type - excluding '@' and '#'.
morgalr wrote:There is [String.charAt(int index)|http://java.sun.com/javase/6/docs/api/java/lang/String.html#charAt(int)] which returns the character at position index. This method can't read your mind though, so charAt(0) will return the very first character regardless of whether it is "good".
There isn't a built in function like String.firstChar() that would give you the first character of any String. You can easily make one though.
In the Character class there is also a static method [isLetter(character)|http://java.sun.com/javase/6/docs/api/java/lang/Character.html#isLetter(int)] which reports "true" if the supplied character is a letter. There are lots of other methods in this class to report on the type of letter.
Perhaps you could put these ideas together: write a loop to inspect each letter in turn until you come to one that is "good".