简体   繁体   English

在“:”之前将某些文本更改为大写

[英]Change the certain text to upper case before ':'

I have a multiline of string, at the end of the line I have ':'.我有一个多行字符串,在行尾我有':'。 now I want to change the word of the whole line before ':' to upper case.现在我想将':'之前的整行单词更改为大写。 how can I change this?我怎样才能改变这个?

var temp= "Professional Endermologie Lipomassage Total Care at £65 (35 minutes)
Professional Endermologie LPG Cellulite Smoothing Treatment at £65 (35 minutes)
Professional Inch Loss Wrap at £80 (2 hours)
Thalgo Polynesia Spa Ritual at £120 (1.30 hours)
Laser Hair removal:";


var rsdata = temp.substring(0, temp.indexOf(":"));
var rsdata = temp.split(':')[0];
data = temp.replace(rsdata, rsdata.toUpperCase());
console.log(data);

Here the sample code i have use to change the particular text.这是我用来更改特定文本的示例代码。

Simple example, using Template Literals for multi-line string:简单示例,将模板文字用于多行字符串:

var text = `Line 1
Line 2
Line 3
Line 4 with colon: after colon`;

text = text.replace(/.+?:/, function(match) {
    return match.toUpperCase();
});

console.log(text);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM