Reactjs 将输入字符串转换为大写
我正在使用react strap在Reactjs中创建一个应用程序。我想将输入字段转换为大写 从谷歌上看,简单地将toUpperCase添加到字段中似乎是可行的,但在VisualStudio代码中这并不是一个选项 我在执行“全部替换”时遇到了类似的问题,但最终使用const字段实现了这一点:Reactjs 将输入字符串转换为大写,reactjs,string,Reactjs,String,我正在使用react strap在Reactjs中创建一个应用程序。我想将输入字段转换为大写 从谷歌上看,简单地将toUpperCase添加到字段中似乎是可行的,但在VisualStudio代码中这并不是一个选项 我在执行“全部替换”时遇到了类似的问题,但最终使用const字段实现了这一点: // replace ":" with "-" const phrase = item.macs; const replaced = phrase.replace(/:/g, '-') item.macs
// replace ":" with "-"
const phrase = item.macs;
const replaced = phrase.replace(/:/g, '-')
item.macs = replaced;
但是,转换为常量字段并不能使toUpperCase可用
我应该怎么做才能将其转换为字符串,以便调用toUpperCase函数
编辑:将引用从toUpper更改为toUpperCase。问题是,此函数不可用
例如,我是这样做的
“我的串”,托珀凯斯
它起作用了。但我无法在Visual Studio代码中使用它,而且如果我编写它,它将被忽略。我相信您正在关注它。要在javascript中生成字符串大写,您可以对其调用.toUpperCase方法。比如说
const foo = 'foo'
const fooUpper = foo.toUpperCase()
console.log(fooUpper) // expected result 'FOO'
我绕过了这个问题,通过在输入项前面加上一个字符,将其视为字符串,如下所示:
item.macs = '' + item.macs;
item.macs = item.macs.replace(/:/g, '-');
item.macs = item.macs.toUpperCase();
之后,所有字符串函数都可用