[英]How to make specific word in string upperCase or lowerCase?
Okay I have a small problem I want to make specific words in this string to be upperCase() or lowerCase(). 好的,我有一个小问题,我想在此字符串中指定特定的单词为upperCase()或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
. 我只想知道如何简单地将某些单词upperCase
lowerCase
或upperCase
。
you can do this way,for any particular word. 您可以针对任何特定字词执行此操作。 here is an example using toUpperCase(). 这是使用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(). 或以这种方式,这是一个使用substring()和toLowerCase()的示例。
text=text.replace(text.substring(0,7),text.substring(0,7).toLowerCase());
From a question in StackOverflow: 来自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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.