admin管理员组文章数量:1026989
Trying to remove ST,+ from this string below. I've tried so many different ways but just can't seem to get it to remove anything from the string at all. Anything I'm doing wrong?
function convertSerialData(valueIn){
valueIn.replace(/ST/i, '');
return valueIn;
}
alert(convertSerialData('ST,+00.8 g '));
Trying to remove ST,+ from this string below. I've tried so many different ways but just can't seem to get it to remove anything from the string at all. Anything I'm doing wrong?
function convertSerialData(valueIn){
valueIn.replace(/ST/i, '');
return valueIn;
}
alert(convertSerialData('ST,+00.8 g '));
Share
Improve this question
asked Sep 2, 2015 at 13:40
thedoggydogthedoggydog
4691 gold badge4 silver badges11 bronze badges
2 Answers
Reset to default 8You don't seem to be assigning the results of the replace:
valueIn = valueIn.replace(/ST,[+]/i, '');
Or, more concisely:
function convertSerialData(valueIn){
return valueIn.replace(/ST,[+]/i, '');
}
valueIn.replace(/ST/i, '');
doesn't modify the string, it returns a new one. You need to use the value returned from the .replace()
function.
Also, if you want to remove more than just ST
, then you just need to update your regex to remove the characters you need.
function convertSerialData(valueIn){
return valueIn.replace(/ST,\+/i, '');
}
Trying to remove ST,+ from this string below. I've tried so many different ways but just can't seem to get it to remove anything from the string at all. Anything I'm doing wrong?
function convertSerialData(valueIn){
valueIn.replace(/ST/i, '');
return valueIn;
}
alert(convertSerialData('ST,+00.8 g '));
Trying to remove ST,+ from this string below. I've tried so many different ways but just can't seem to get it to remove anything from the string at all. Anything I'm doing wrong?
function convertSerialData(valueIn){
valueIn.replace(/ST/i, '');
return valueIn;
}
alert(convertSerialData('ST,+00.8 g '));
Share
Improve this question
asked Sep 2, 2015 at 13:40
thedoggydogthedoggydog
4691 gold badge4 silver badges11 bronze badges
2 Answers
Reset to default 8You don't seem to be assigning the results of the replace:
valueIn = valueIn.replace(/ST,[+]/i, '');
Or, more concisely:
function convertSerialData(valueIn){
return valueIn.replace(/ST,[+]/i, '');
}
valueIn.replace(/ST/i, '');
doesn't modify the string, it returns a new one. You need to use the value returned from the .replace()
function.
Also, if you want to remove more than just ST
, then you just need to update your regex to remove the characters you need.
function convertSerialData(valueIn){
return valueIn.replace(/ST,\+/i, '');
}
本文标签: Javascript replace not working for some reasonStack Overflow
版权声明:本文标题:Javascript replace not working for some reason - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745670007a2162401.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论