1

Okay I have a small problem I want to make specific words in this string to be upperCase() or lowerCase().

This is what I originally tried:

function lcFunct() {
        var a = "WelCome TO the Test I WANT all THIS to be LoWeRCAse"
        document.getElementById("tests").innerHTML = a.str.replace(6,12).toUpperCase()
}

All I want to know is how to simply make certain words lowerCase or upperCase.

Filipe
  • 1,788
  • 2
  • 13
  • 18

2 Answers2

2

you can do this way,for any particular word. here is an example using toUpperCase().

var text = "WelCome TO the Test I WANT all THIS to be LoWeRCAse";
text=text.replace("WelCome","WelCome".toUpperCase());

or this way, here is an example using substring() and toLowerCase().

text=text.replace(text.substring(0,7),text.substring(0,7).toLowerCase());
0

From a question in StackOverflow:

var searchMask = "HELLO WORLD";
var str="Look this HELLO WORLD and this hello world and say HELLO WORLD";
var replaceMask = searchMask.toLowerCase();
var regEx = new RegExp(searchMask, "ig");

var result = str.replace(regEx, replaceMask);
alert(result);
You can write "Hello World" or "HellO woRld" and the code works in both cases.
Community
  • 1
  • 1