Solved

underscore to space and capitalize first letters

Posted on 2006-11-14
5
782 Views
Last Modified: 2008-02-01
Hello,

I use the following code:

'window.status=\'' + this.items[i].url.replace("\.\./", "").replace("\./", "").replace("\.html", "").replace("\.htm", "").replace("\.php", "") + '\'; return true" ' +
 (thanks, Basilisci: http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_22060261.html)

Now I want to change it so that _ becomes a space and each word is capitalized, like this:

      hello_world

 should become

      Hello World

Any ideas?

Thanks!
0
Comment
Question by:hankknight
5 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 400 total points
ID: 17940372
'window.status=\'' + this.items[i].url.replace("\.\./", "").replace("\./", "").replace(/\.(html|htm|php)/ig, "").replace.replace(/_/g, ' ').toUpperCase() + '\'; return true" ' +

-r-
0
 
LVL 16

Author Comment

by:hankknight
ID: 17940476
Thanks,  it gives me a JavaScript error, but I haven't done any testing yet.  I will let you know.
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 400 total points
ID: 17940524
Probably on the errorous part replace.replace(/ (there should only be a single replace)

-r-
0
 

Assisted Solution

by:IAmMenno
IAmMenno earned 50 total points
ID: 17940560
Hm, I just wrote this function, and then I see Roonaan already answered this. Well, here it is anyway:

function rpStr(text){
var tmpStr = new String(text);
      
      return tmpStr.replace(/_/g, " ").replace(/(^| )./g, function(a){
            return a.toUpperCase();
      });
}

It very neatly replace underscores and capitalizes words. Enjoy.
0
 
LVL 9

Assisted Solution

by:ftaco96
ftaco96 earned 50 total points
ID: 17940710
'window.status=\'' + this.items[i].url.replace("\.\./", "").replace("\./", "").replace(/\.(html|htm|php)/ig, "").replace(/_/g, ' ').toLowerCase().replace(/\b[a-z]/g, titleCase) + '\'; return true" ' +

and have this function in the page...
        function titleCase() {
            return arguments[0].toUpperCase();
        }

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question