You could add 32 or subtract 32 from the ascii value depending on whether it's lower or uppercase.... A simpler solution is creating a substring and calling the toUpperCase() method:
String newString = (oldstring.substring(0,1)).toUpperCase();
NOTE: It's not tested so don't be suprised if that doesn't work.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Strings are final. You can't change them once they're created, so you're going to have to create a new String based on the old one.
In your specific case you could use String newString = s.replace('b', 'B'); but keep in mind that that will replace ALL lowercase b's in the string with uppercase ones, and of course work only on lowercase b's.
A more generic solution would be something along the lines of String newString = s.substring(0,1).toUpperCase()+s.substring(1); but that will get rather slow if you call it a lot and can use up a lot of memory.
A better solution if you use it a lot would be to create a function that turns the string into a character array, update the first character of that (if it is within the range of lowercase letters), and return a new String generated from that character array.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337