简体   繁体   English

如何在字符串upperCase或lowerCase中制作特定单词?

[英]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 lowerCaseupperCase

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); 
You can write "Hello World" or "HellO woRld" and the code works in both cases. 您可以编写“ Hello World”或“ HellO woRld”,并且代码在两种情况下均有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript中的区域设置特定的小写/大写字符串操作 - Locale specific lowercase/uppercase string manipulation in JavaScript 如何使我的前缀适用于小写和大写? - how to make my prefix works on lowercase and uppercase? 如何使查询忽略小写和大写? - How to make Query ignores lowercase and uppercase? 如何在 JavaScript 中按大写和小写拆分字符串? - How to split a string by uppercase and lowercase in JavaScript? 我有这个 IF 说:如果字符串的索引是 == 0,则将其设为大写,但 output 是小写的索引 0 - I have this IF saying that: if the index of the string is == 0 then make it UpperCase, but the output is index 0 in lowercase 如何在没有toUppercase()函数的情况下将小写字符串转换为大写字符串 - How to convert lowercase string to uppercase string without toUppercase() function 如何使jQuery活动状态忽略大写或小写进行url检测 - How to make jQuery active state ignore uppercase or lowercase for url detection 如何将一半的srting用大写,另一半用小写? - how to make half of the srting in uppercase and the other half in lowercase? 如何制作从大写变为小写的单个按钮 - how to make a single button that changes from uppercase to lowercase 如何使我的搜索表单使用大写和小写 - How can I make my search form work with uppercase and lowercase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM