Char to uppercase?

Hi, I am trying to convert all letters entered by the user to uppercase while leaving all the symbols and numbers alone...
char a,b;
b=a.toUpperCase();
apparently, this toUpperCase() method doesn't work...
Help please~~~
Thanks,

JoachimSauer wrote:
morgalr wrote:
it used to be used a lot in the days of EBSIDC(sp) and ASCII, so you wouldn't have to two conversions.But it's about time to let it die. Computers can be a lot smarter about characters now. And there's an awful lot of people who don't speak english (at least not as their primary language) and who use characters that are not contained in ASCII (or EBCDIC).
There's no use in badly re-implementing something in a limited way, when a perfectly functioning alternative is available easily.
Don't try to re-implement Character.toUpperCase() (or worse: String.toUpperCase()). You will get it wrong, unless you have a very narrow definition of "character".Hey, what put a bug up your bonnet? If you look at the original post I did you'll see that the Character.toUpperCase was listed as the preferred method to use over the old way.
You can also do: c = c - 'a' + 'A';
Not as good as c = Charater.toUpperCase(c); I do believe that people are able to look, and read and decide for themselves, english speaking or not...
c = Character.toUpperCase(c); means the same in English Java as it does in Japan or in Mexico. In some situations the built in API functions for conversions are not allowed by instructors--and rightly so--they are looking to teach the students what the pit fall and benefits of one method over another is--so when I put out something like that mentioned post, I leave it to the user to decide what is appropriate to use in their situation.

Similar Messages

  • How can i transform lowercase char in uppercase char automatica​lly

    I would like that when you write lowercase char in a control string these char be converted automaticaly in uppercase char in this string

    wire the control to the "To Upper Case" function and that output to a
    local variable of your control.
    niko
    tlap wrote:
    > I would like that when you write lowercase char in a control string
    > these char be converted automaticaly in uppercase char in this string

  • Manipulating chars

    Hi everyone,
    I'm still new to Java (and programming!). Can anyone advise me on how to manipulate chars, particularly how to convert a given lowercase char to uppercase? The only way I can do it right now is to convert to String and use toUpperCase() method, but this seems clumsy.
    Thanks!

    Just to clarify, pervel is reffering to the java.lang.Character.toUpperCase() method. The Character class is a wrapper class - one exists for every primitive type (Integer, Float etc...) and they are mainly of use when you have a library API which demands to return or accept as an argument something of type java.lang.Object - you can't pass an char since this is not an object.
    In this example you would take your char variable...
    char c = 'c';
    ...place it in a wrapper...
    Character myChar = new Character(c);
    ...then set the original variable to the return value of the method...
    c = myChar.toUpperCase();
    ...the variable c will now == 'C'.
    Wrappers are good in this sense but if you are, for example, converting a large text file to upper-case, you will be creating a huge number of objects making your code slow and bloating out the memory - for speed use the arithmetic algorithm in the first posting / to show you know your way around the API, use the wrapper class...

  • Use query string between two custom New Form

    Hi guys,
    i have a New Form . In this  form i have  a button that open(onClick) another list form (it is a  different list). I have to pass a field value from the first form to the other . How can i do this using query string?Help please!
    Thank you!

    To pass some value with query string, you just need to open the form url with the querystring parameters (jquery needed):
    var url = '<yourlist>/newform.aspx?parameter1=' + $('input[Title="Title"]').val()
    SP.UI.ModalDialog.ShowPopupDialog(url)
    on the second newform.aspx, you can grab the querystring parameters with the Sharepoint native function "_spGetQueryParam('<lower case query key>')"
    var x = _spGetQueryParam("parameter1")
    Note: make sure you use the key as lowercase, even you if pass it with chars in uppercase.

  • Convert letters into numbers

    I need to write a method that converts letters from a word into a number according to the telephone buttons.
    I figured I was at a good start by putting the string of the word into a character array, but how would I assign each of those letters to its corresponding number?
    Thanks in advance.

    changes to code that fills the hashmap. more concise (less interpretable)
    import java.util.HashMap;
    import java.util.Map;
    class HashMapTester2
        private Map<Character, Integer> phoneHash;
        // constructor
        // for converting alphabetical characters to numbers based on the
        // phone dialing pad.
        public HashMapTester2()
            phoneHash = new HashMap<Character, Integer>();
            fillMap();
        private void fillMap()
            for (char myChar = 'a'; myChar <= 'z'; myChar++)
                int distanceFrom_a = (int)(myChar - 'a');
                if (myChar > 'r') // 's' hangs back w/ the pqr group.
                    distanceFrom_a -= 1;
                if (myChar > 'y')  // 'z' hangs back w/ the wyz group.
                    distanceFrom_a -= 1;
                // 2 is due to the numbers starting at 2
                // 3 is due to the letters being grouped in 3's, all sharing
                // the same number.
                int number = (int)(2 + (distanceFrom_a) / 3);
                phoneHash.put(myChar, number);  // insert reg char
                // insert uppercase version, same number
                phoneHash.put(Character.toUpperCase(myChar), number);
        // convert string to a long number based on results of
        // the string's characters run through the hashmap
        public long convertStr(String s) throws IndexOutOfBoundsException
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.length(); i++)
                char myChar = s.charAt(i);
                if ((myChar >= 'a' && myChar <= 'z') || (myChar >= 'A' && myChar <= 'Z'))
                    sb.append(phoneHash.get(myChar));   
                else
                    throw new IndexOutOfBoundsException();
            return Long.valueOf(sb.toString());
        public static void main(String[] args)
            HashMapTester2 hmt = new HashMapTester2();
            System.out.println(hmt.convertStr("aaa"));
            System.out.println(hmt.convertStr("What"));
            System.out.println(hmt.convertStr("the"));
            System.out.println(hmt.convertStr("heck"));
            System.out.println(hmt.convertStr("Fubar"));
            System.out.println(hmt.convertStr("Snafu"));
            System.out.println(hmt.convertStr("abcdefghijklm"));
            System.out.println(hmt.convertStr("nopqrstuvwxyz"));
            System.out.println();
            System.out.println(hmt.convertStr("abc"));
            System.out.println(hmt.convertStr("def"));
            System.out.println(hmt.convertStr("ghi"));
            System.out.println(hmt.convertStr("jkl"));
            System.out.println(hmt.convertStr("mno"));
            System.out.println(hmt.convertStr("pqrs"));
            System.out.println(hmt.convertStr("tuv"));
            System.out.println(hmt.convertStr("wxyz"));
    }

  • T440s - keyboard is broken after BIOS update to 2.25

    Hi,
    today I've updated my Lenovo T440s BIOS to 2.25 version. The update was performed using Software updates in Lenovo Solution Center and everything was successful.
    After computer reboot the keyboard has been mulfunctioned:
     when I hold Windows Key the following char is produced {}Y (moreover on Windows 8.1 speekers turn downs, metro apps panel from W8.1 is show and next chars are uppercase)
    when I press/hold Right arrow key the following char is produced ń
    This is not OS dependent issue - I tried to use Rigth arrow in BIOS menu and it doesn't work.
    Do you have any suggestions what to do? Or any tips how to restore previous version of BIOS?
    I'm looking forward to hearing any tips.
    qinto

    Roll-back to 2.24 version fixed the problem, but the issue with current BIOS version remains.
    EDIT: Unfortunately the roll-back hasn't solved the problem - working with keys mentioned above is better, but still holding Win Key and Right Arrow causes the same problems.
    Greets,
    qinto

  • Read txt file 1 char @ time cnvrt to uppercase problem

    I am trying to get the following 2 problems solved. My input file is below and my output is below along with the code.
    Can anyone fix this and explain what I am doing wrong? Thank You in advance!
    (1) Any string of two or more blanks symbols is replaced by a single blanks.
    (2) All sentences start with an upper case letter.
    Input A://DataIn.txt = How me? you good.
    Output A://DataOut.txt = H o w m e Y U G O . ��
    import java.io.*;
    public class NumberFormat
    private DataInputStream inputStream = null;
    private DataOutputStream outputStream = null;
    *(1) Any string of two or more blanks symbols is replaced by a single blanks.
    (2) All sentences start with an upper case letter.
    public static void main(String[] args) throws java.io.IOException
    NumberFormat twoTimer = new NumberFormat();
    twoTimer.connectToInputFile();
    twoTimer.connectToOutputFile();
    twoTimer.readInput();
    twoTimer.closeFiles();
    System.out.println("Check A:/DataOut.txt Now");
    public void connectToInputFile()
    String inputFileName = getFileName("Enter input file name: A://DataIn.txt");
    try
    inputStream =
    new DataInputStream(
    new FileInputStream(inputFileName));
    catch(FileNotFoundException e)
    System.out.println("File " + inputFileName
    + " not found.");
    System.exit(0);
    public void connectToOutputFile()
    String outputFileName = getFileName("Enter output file name: A://DataOut.txt");
    try
    outputStream = new DataOutputStream(
    new FileOutputStream(outputFileName));
    catch(FileNotFoundException e)
    System.out.println("Error opening output file "
    + outputFileName);
    System.out.println(e.getMessage());
    System.exit(0);
    private String getFileName(String prompt)
    String fileName = null;
    System.out.println(prompt);
    fileName = SavitchIn.readLineWord();
    return fileName;
    //===========================================================================
    public void readInput()
    char prevChar = ' ';
    try
    char nextChar;
    String result = "";
    boolean done1 = false;
    boolean done2 = false;
    char next;
    do
    next = (char) (inputStream.read()); // <== Read input 1 Character @ time
    if (next == '\n')
    done1 = true;
    if (next == ' ' && next == prevChar)
    prevChar = next;
    else
    if (next == '.' || next == '!' || next == '?')// <== Capitalize next input Character
    do
    next = ' ';
    outputStream.writeChar(next);
    next = (char) (inputStream.read());
    if (next == '\n')
    done2 = true;
    next = (char) (inputStream.read());
    // next = (char) (inputStream.readNonwhiteChar()); ?????????????
    if (next == '\n')// <== never gets to end of file
    done2 = true;
    outputStream.writeChar(Character.toUpperCase (next));
    prevChar = next;
    while (!done2);
    else
    outputStream.writeChar(next);
    prevChar = next;
    while (!done1);
    catch(EOFException e)
    //Do nothing. This just ends the loop.
    System.out.println("Do Nothing Here");
    catch(IOException e)
    System.out.println(
    "Error: reading or writing files.");
    System.out.println(e.getMessage());
    System.exit(0);
    public void closeFiles()
    try
    inputStream.close();
    outputStream.close();
    catch(IOException e)
    System.out.println("Error closing files "
    + e.getMessage());
    System.exit(0);

    This line looks fishy:
    if (next == ' ' && next == prevChar)
    prevChar = next;Try:
    if (next == ' ' && next == prevChar)
    next = "";That should take care of the extra blanks, though I didn't test it myself, and could very well be wrong.
    Not sure about the uppercase, though I imagine it must be reading the ToUpperCase every time after the first period.

  • Tokens with digits and alpha. chars not converted to uppercase

    Hi
    We are using Oracle9i Enterprise Edition Release 9.2.0.2.0.
    We have made a CONTEXT Index with the BASIC_LEXER. (Only thing we have changed is BASE_LETTER=YES)
    The defaults says, that tokens are converted to all uppercase. But if a token contains digits and alphanumeric chars it remains mixed case.
    For example:
    Oracle9i is stored in the token table Oracle9i and not ORACLE9I.
    Therefore a search with CONTAINS for this token is case sensitive.
    Is this a bug or are we doing something wrong?
    Best regards,
    Beat

    This is a bug in 9.2.0.2, and is fixed in 9.2.0.3. Bug # is 2684307.
    Tom Best

  • Converting a char input to uppercase

    hello,
    what code would i use to convert the input of a char from the user to uppercase
    thanks in advance

    char someChar;
    someChar = whatever_method_you_use_to_get_the_input_char();
    someChar = Character.toUpperCase(someChar);or
    char someChar = Character.toUpperCase(whatever_method_you_use_to_get_the_input_char());Probably you should post questions like this on the New To Java forum.

  • Apple bluetooth keyboard don't wrote uppercase chars

    Hi everyone! I trying to clean my keyboard and after i finished. some chars like "q" "w" "e" "r" and other don't wrote with shift in uppercase. But if i use caps lock, all ok. i can't all time switch between caps lock. How i can fix it?
    Thanks!

    Hello:
    I suspect the keyboard is faulty.
    However, before you replace it, try resetting the PRAM and SMC (instructions are in knowledge base articles).
    Barry

  • How to check whether a char string is in uppercase or not

    Hi,
    I know how to convert strings to change strings to uppercase or lowercase, but is there any function to check, beforehand, if the field is in uppercase, for instance ? The intention here is simply to spare processing in situations where the string is already in uppercase, and thus not needing any further processing (given I want to turn the string into uppercase.)
    Thanks in advance,
    Avraham

    Hi Avraham ,
    To check whether the string is in upper case or not use CA keyward.
    To check  try the following code  ---
    DATA : W_STRING(5) TYPE C,
    W_ABCDE(26) TYPE C VALUE 'abcdefghijklmnopqrstuvwxyz'.
    w_string = 'abcd'.
    IF W_STRING CA W_ABCDE.
    TRANSLATE w_string TO UPPER CASE.
    ELSE.
    MESSAGE 'It is a uppercase string' TYPE 'S'.
    ENDIF.
    Try this link  this will definitely help you -
    https://wiki.sdn.sap.com/wiki/display/ABAP/Validationofastringintermsof+case
    Regards
    Pinaki

  • CS3/4 Is there a char for an XML tag?

    I have a script that gets the value of an XML element. If some of my users make the tagged text wrong, then I get an extra invisible character in the string, and that string is used to make a file name, and then I have problems later since this invisible character is illegal in the filesystem. I'm working on Mac, if it might matter.
    So, is there a character that is the equivalent of one of the tagging brackets? Here's how my users are mistakenly making their tags.
    Make a new document
    draw a text frame, type a couple characters like "foobar"
    open tag pallet. Make a new tag like "tag1"
    select all text with the text tool.
    apply tag to text. You should NOT see tag brackets on the text by default because the entire text frame is tagged.
    now select all the text EXCEPT the last character. If you typed "foobar" only select "fooba"
    Apply tag. Now you will see tag brackets.
    Now unselect text.
    Use arrow keys to key forward through text. When  you get to the closing bracket, you will have to key over 2x to get the cursor to move. This suggests to me there is an invisible character.
    Now when I am running my script, it sometimes picks up the invisible character. I need to be able to strip it off.
    Because the length of text varies, I can't chop off "char -1" because sometimes the text is tagged correctly and I don't have the invisible char. I think it's Unicode (maybe?).
    If you post some code, please use Applescript. Thx.
    Thanks,
    Chris

    .. and you can remove them with
    newstr = oldstr.replace(/\uFEFF/g, "");
    (note the UPPERCASE unicode -- for some reason it doesn't work with lowercase \ufeff, while it does in regular strings!)
    .. drat -- this is javascript ..

  • Changing to uppercase?

    I'm trying to change the first letter in a name to uppercase, I dont appear to have a problem chaning the letter to uppercase but I cant change the string. any help would be much appreciated.
    thanx.
    String name = "james";
              //Get the first character:
              char first = name.charAt(0);
              //Make the char uppercase:
              first = Character.toUpperCase(first);
              //replace the first character:
              StringBuffer nameBuffer = new StringBuffer(name);
              nameBuffer.replace(0, 1, new String(first));
              name = nameBuffer.toString();
              System.out.println(name);

    String name = "james";
    char[] chars = name.toCharArray();
    chars[0] = Character.toUpperCase(chars[0]);
    name = new String(chars);

  • How to read char from console

    Hi can any body help me..
    I want to read char from keybord. withought pressing ENTER.
    I am not sure how i can do it. I can't use
    BufferedReader br = new  BufferedReader(new InputStreamReader ( System.in )) ;
    char key ;
    key = (char )br.read() ;
    cuz i have to press ENTER every time to read char.
    Thanks in advance.

    try this,I' have found a part on Internet
    package exercises;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    * questa � la classe d' esempio per leggere l'input dalla console*/
    public class Echo {
    public static void main(String args[]) throws Exception{
    // This is where the magic happens. We have a plain old InputStream
    // and we want to read lines of text from the console.
    // To read lines of text we need a BufferedReader but the BufferedReader
    // only takes Readers as parameters.
    // InputStreamReader adapts the API of Streams to the API of Readers;
    // receives a Stream and creates a Reader, perfect for our purposes.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String input = "";
    while(true){
    System.out.print("ECHO< ");
    //As easy as that. Just readline, and receive a string with
    //the LF/CR stripped away.
    input = in.readLine();
    //Is a faster alternative to: if (input == null || input.equals(""))
    //The implementation of equals method inside String checks for
    // nulls before making any reference to the object.
    // Also the operator instance of returns false if the left-hand operand is null
    if ("".equals(input)){
    break;
    }else
    // Here you place your command pattern code.
    if ("ok".equals(input)){
    System.out.println("OK command received: do something �");
    //Output in uppercase
    System.out.println("ECHO> " + input.toUpperCase());
    System.out.println("ECHO> bye bye");
    //We exit without closing the Reader, since is standard input,
    // you shouldn't try to do it.
    // For all other streams remember to close before exit.
    }

  • Convert char .toUpperCase

    Hello again, sorry I have another really nooby question I know it, I don't understand these things with the examples and methods they have posted though.
    Basically the user inputs a string (their name), and I take the first character out of that string and place it in a char variable.
    I then want to check if it is lowercase, if not then it passes, otherwise it needs converting to uppercase and putting back into the string (not sure if converting the char automatically changes it in the string too).
    e.g "enter your name" andrew
    --change small a to big A
    "display name" Andrew
    Yes, I feel extremely stupid, but i've tried to figure it out and I can't, if anybody would mind helping such a newbie i'd appreciate it thanks.
    /*Program to print
    *persons details
    *in a table like
    *format with headers
    import java.util.*;
    public class FormattingOutput
         public static void main (String[] args)
         Scanner kybd = new Scanner(System.in);
         System.out.println("Please enter your first name");
         String firstN = kybd.next();
         System.out.println("Please enter your surname");
         String lastN = kybd.next();
         System.out.println("Please enter your age");
         int age = kybd.nextInt();
         System.out.println("Please enter your nationality");
         String nation = kybd.next();
         System.out.println("Please enter your weekly salary including currency");
         String wage = kybd.next();
         System.out.println("Here is the information you entered");
         char firstCF = firstN.charAt(0);
         char firstCS = lastN.charAt(0);
         char firstNA = nation.charAt(0);
         if (firstCF.isLowerCase)
         firstCF = firstCF.toUpperCase;
    //     if (firstCS.isLowerCase)
    //     firstCS = firstCS.toUpperCase;
    //     if (firstNA.isLowerCase)
    //     firstNA = firstNA.toUpperCase;
    }Edit -- it's the same error I couldn't figure out earlier, something to do with dereferencing because i'm using string operations on chars or something, I don't get it.
    Message was edited by:
    Drew___

    Cheers Ramjane, I feel a bit like Homer "D'oh", but
    thats about the only way I can learn stuff right
    there. Thx for the help.
    I can't award stars to everyone :( so i'm giving them
    to you, sorry the rest of you :P
    Edit-- ah I see, thanks for the explanation to
    concotenation. We haven't covered that in the module
    so that helps :). Also just realised I could have
    split up the stars for each of you, I messed up
    sorry, will do next time.
    Message was edited by:
    Drew___Reply #3 was actually a better reply.
    Kaj

Maybe you are looking for

  • The built-in "Notes" apps in my ipad2 wont open, when i click it immedieately it closes...help!

    The built-in "Notes" apps in my ipad2 wont open, when i click it immedieately it closes...help!... Thanks

  • Weblogic no-stage mode deployment from remote machine

    Context: 1. Build server is on machine A, where ant script builds the file and package ear 2. WLST deployment.py script is on build server (machine A). 3. weblogic admin server in machine B. The managed servers are on machine B and C. 4. ear file is

  • Filetype out of unzipped XSTRING

    Hello developers! Hope anybody of you can help me with question. I created a report with that i generate an interactive form, zip it and send it out as attachement by miall to my customers. Then i get from the customers the zip file back. But the zip

  • Gnome panel is freaking out

    hey there, maybe one of you have seen this one. sometimes while running gnome, the gnome-panel just starts freaking out. jittering back and forth, my cpu spikes and stays at 100%. i can stop it with a killall gnome-panel, but i need it to go away, an

  • My After Effects Download gets stuck on 52%

    Hi, I am currently installing the After Effects CC Trial on Creative Cloud, the download has been fast and fine up until now. It is stuck on 52% and has been for about half an hour, I tried to cancel it, and reinstall it but it is still getting stuck