Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:41:45+00:00 2026-06-09T17:41:45+00:00

I have a javascript case conversion problem which I cannot solve due to non-English

  • 0

I have a javascript case conversion problem which I cannot solve due to non-English letters. My main concern is the Turkish alphabet.

What I need to do is this:

  • hello world => Hello World
  • HELLO WORLD => Hello World
  • hELLO wOrLd => Hello World

Here is what I’ve accomplished so far:

String.prototype.turkishToUpper = function(){
    var stringlow = this;
    var letterslow = { 'i': 'İ', 'ş': 'Ş', 'ğ': 'Ğ', 'ü': 'Ü', 'ö': 'Ö', 'ç': 'Ç', 'ı': 'I' };
    stringlow = stringlow.replace(/(([iışğüçö]))/g, function(letterlow){ return letterslow[letterlow]; })
    return stringlow.toUpperCase();
}

String.prototype.turkishToLower = function(){
    var stringup = this;
    var lettersup = { 'İ': 'i', 'I': 'ı', 'Ş': 'ş', 'Ğ': 'ğ', 'Ü': 'ü', 'Ö': 'ö', 'Ç': 'ç' };
    stringup = stringup.replace(/(([İIŞĞÜÇÖ]))/g, function(letterup){ return lettersup[letterup]; })
    return stringup.toLowerCase();
}

String.prototype.toProperCase = function () {
    return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).turkishToUpper() + txt.substr(1).turkishToLower();});
};

But this does not give me the correct results and I am suspecting the regex replace not being usable on unicode, but ascii.

When I test with Turkish characters, I get wrong results.

  • şeker becomes şEker instead of Şeker
  • çoban ırmak becomes çOban ıRmak intead of Çoban Irmak

Also, if this can ever get resolved, I need an icing on the cake to separate words not only by spaces, but also by some other stop characters such as : – = / etc so that

  • hello-world becomes Hello-World
  • hello:world becomes Hello:World

I’ve read through many similar questions here on SO, but no luck so far.

Thanks

Note: I think this is called Title Case but some have argued that it is Pascal Case. To be frank, I am interested in resolving the unicode issue (which I believe is the root cause) rather than semantics, so please forgive me if I’ve used wrong terminology 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:41:47+00:00Added an answer on June 9, 2026 at 5:41 pm

    Standalone function:

    function toProperCase(s){
        return s.replace(/([^\s:\-])([^\s:\-]*)/g,function($0,$1,$2){
            return $1.toUpperCase()+$2.toLowerCase();
        });
    }
    

    Or for extending of String.prototype:

    String.prototype.toProperCase=function() {
        return this.replace(/([^\s:\-])([^\s:\-]*)/g,function($0,$1,$2){
            return $1.toUpperCase()+$2.toLowerCase();
        });
    }
    
    "çoban ırmak becomes çOban ıRmak intead of Çoban Irmak Hello-wOrld".toProperCase();
    // "Çoban Irmak Becomes Çoban Irmak Intead Of Çoban Irmak Hello-World"
    

    Update:

    Next code uses custom functionality for converting locale specific chars (tested partially). Code adds functions into String.prototype: toLocaleProperCase2, toLocaleLowerCase2 and toLocaleUpperCase2.

    (function(){
        // locale specific chars
        // IMPORTANT: name of locale must be always in lower case (for "tr-TR" locale - "tr-tr") !!!
        var localeInfos={
                "tr-tr": { lower: { i:"İ", ı:"I", ş:"Ş", ğ:"Ğ", ü:"Ü", ç:"Ç", ö:"Ö" },
                           upper: { İ:"i", I:"ı", Ş:"ş", Ğ:"ğ", Ü:"ü", Ç:"ç", Ö:"ö" } }
            },
            localeInfo;
        // helper vars
        var mask="\\s:\\-", // add additional delimeters chars to the mask if needed
            rg=new RegExp("([^"+mask+"])([^"+mask+"]*)","g");
        var fnToLocaleLower=function(s){ return localeInfo.upper[s]; },
            fnToLocaleUpper=function(s){ return localeInfo.lower[s]; },
            fnToProper=function($0,$1,$2){
                if(localeInfo){
                    if(localeInfo.lower.hasOwnProperty($1))$1=localeInfo.lower[$1];
                    $2=$2.replace(localeInfo.upperSearchRegExp,fnToLocaleLower);
                }
                return $1.toUpperCase()+$2.toLowerCase();
            };
        // helper calculations
        var localeInfosKeys=Object.keys(localeInfos);
        for(var i=0;localeInfo=localeInfos[localeInfosKeys[i]];i++){
            localeInfo.lowerSearchRegExp=new RegExp("["+Object.keys(localeInfo.lower).join("")+"]","g");
            localeInfo.upperSearchRegExp=new RegExp("["+Object.keys(localeInfo.upper).join("")+"]","g");
        }
    
        // extending String.prototype
        String.prototype.toLocaleProperCase2=function toLocaleProperCase2(locale){
            localeInfo=localeInfos[arguments.length?locale.toLowerCase():null];
            return this.replace(rg,fnToProper);
        };
        String.prototype.toLocaleLowerCase2=function toLocaleLowerCase2(locale){
            return ((localeInfo=localeInfos[arguments.length?locale.toLowerCase():null]) ?
                    this.replace(localeInfo.upperSearchRegExp,fnToLocaleLower):
                    this).toLowerCase();
        };
        String.prototype.toLocaleUpperCase2=function toLocaleUpperCase2(locale){
            return ((localeInfo=localeInfos[arguments.length?locale.toLowerCase():null]) ?
                    this.replace(localeInfo.lowerSearchRegExp,fnToLocaleUpper) :
                    this).toUpperCase();
        };
    })();
    

    // testing
    var sss="çoban ırmak ibecıoimes çOban ıRmak intead of Çoban IrImaİk Hello-wOrld";
    console.log("Origin:    ", sss);
    console.log("Proper TR: ", sss.toLocaleProperCase2("tr-TR"));
    console.log("Proper:    ", sss.toLocaleProperCase2());
    console.log("Lower TR:  ", sss.toLocaleLowerCase2("tr-TR"));
    console.log("Lower:     ", sss.toLocaleLowerCase2());
    console.log("Upper TR:  ", sss.toLocaleUpperCase2("tr-TR"));
    console.log("Upper:     ", sss.toLocaleUpperCase2());
    
    // Origin:    çoban ırmak ibecıoimes çOban ıRmak intead of Çoban IrImaİk Hello-wOrld
    // Proper TR: Çoban Irmak İbecıoimes Çoban Irmak İntead Of Çoban Irımaik Hello-World
    // Proper:    Çoban Irmak Ibecıoimes Çoban Irmak Intead Of Çoban Irimaik Hello-World
    // Lower TR:  çoban ırmak ibecıoimes çoban ırmak intead of çoban ırımaik hello-world
    // Lower:     çoban ırmak ibecıoimes çoban ırmak intead of çoban irimaik hello-world
    // Upper TR:  ÇOBAN IRMAK İBECIOİMES ÇOBAN IRMAK İNTEAD OF ÇOBAN IRIMAİK HELLO-WORLD
    // Upper:     ÇOBAN IRMAK IBECIOIMES ÇOBAN IRMAK INTEAD OF ÇOBAN IRIMAİK HELLO-WORLD
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Javascript function defined in the main index.html file. One part of this
I have JavaScript code which copies the value of input file and paste it
In the case that the user doesn't have Javascript activated, in order to draw
I have a javascript function below to move from select multiple box A which
At the moment, I have a Javascript (JQuery) front-end which periodically makes requests to
I have to check some strings using JavaScript but case sensitivity is causing problems.
i have a javascript problem there are three html page like 'page1.html', 'anotherPage.html' and
I have a javascript function which supposed to check whether a task is completed.
I have a Javascript function which calls a PHP script on my server. In
I have a javascript function which is called onclick of a button. It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.