Java String Uppercase

Accname

2D-Graphics enthusiast
Reaction score
1,465
Call me stupid if you want but i have problems of converting a String in java to all caps.
I am not talking about literals here, like abc etc, but rather numbers and special signs.
I want to get the same effect like pressing shift/capslock while typing.

I know i could make a hashtable which maps strings to strings but i hope there is a better way.

Thanks for the help.
 
I don't see much else.. you could convert it to a byte array and then do some integer stuff for like 1-9 since those match up nicely in UTF-8, but not much else does... no clue what would be faster
 
It's an issue because it depends on the keyboard mapping you're using. For instance, I'm using Canadian French which means shift + 2 gives ". It wouldn't on let's say Canadian English...

Anyway, I would use a 2D char array like this:

Code:
final char[][] MAP = new char {{'1','!'},{'2','"'},{'3','/'}}; // etc...
Then a for loop should easily allow you to convert it.
 
I hoped there would some kind of tool which is using the current locale so that it would work with every keyboard mapping and language.
 
I think you're out of luck. I don't think locale can be used for that, nor do I know of any other Java class that can do this for you.
A table seems to be the most sensible solution.
 
>_< Not funny.
So what should i do? Force some kind of standard keyboard layout in my game?
That does not sound very nice...
 
You can also query the user's language through the locale, determine their layout (e.g. FR_fr => AZERTY) and use a different table for each keyboard layout.

Or allow the user to select it.

Those would be my best guesses.
 
Yeah, i guess i have to do that. There is no other way -.-
Thank you guys.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top