CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2022
    Urbana, Illinios

    JavaScript String Transformation: Converting Text to Uppercase

    I'm working on a JavaScript project where I need to manipulate text strings, and I came across the toUpperCase() method. While I understand its basic functionality of converting text to uppercase, I have a specific use case where I'm encountering unexpected results.

    Here's a simplified example of what I'm trying to do:

    const text = 'Hello, world!';
    const uppercaseText = text.toUpperCase();
    console.log(uppercaseText); // Outputs: 'HELLO, WORLD!'
    This works perfectly for most text, but when I have special characters or accented letters, the behavior is not what I expected. For example:

    const specialText = 'Café au lait';
    const uppercaseSpecialText = specialText.toUpperCase();
    console.log(uppercaseSpecialText); // Outputs: 'CAFÉ AU LAIT'
    The accented 'é' remains unchanged. Is there a way to make the toUpperCase() method handle these special characters and accented letters as well so that the entire text is transformed to uppercase? I looked online on many sites, but I was unable to find the answer. Any tips or code snippets on how to implement this behavior, particularly while working with multilingual content, would be very appreciated. I appreciate your help, and
    Last edited by 2kaud; September 27th, 2023 at 03:20 AM. Reason: web site reference removed

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: JavaScript String Transformation: Converting Text to Uppercase

    Sorry, but I don't see that "accented 'é' remains unchanged".
    Instead, what I see from your post is: "Outputs: 'CAFÉ AU LAIT'"
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2001
    Sunny South Africa

    Re: JavaScript String Transformation: Converting Text to Uppercase

    Sorry, I'm a bit late to the party..

    Interesting question.

    The accented e/E will not become uppercase as it is a Unicode character and not a standard character.

    I will not go into much detail on Unicode characters as I will write pages and pages worth.

    Luckily HTML has a way of identifying special characters such as the accented e/E.

    The HTML code for the accented E would be: É whereas the HTML code for the accented e would be: é - See the difference?

    So, I'd advise to first try to identify the correct symbol through JavaScript then convert it to the smaller version. But, I'd determine the special symbol first through the charCodeAt() method prior to doing any further string manipulation

    Best I'd advise you to do is to try and make use of the character's built in

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width