admin管理员组文章数量:1315300
I need to format a string for parison purpose. Lets say we have Multiple Choice I want to convert it to multiplechoice So white spaces removed, any special characters removed and lowercase.
I need to do this in SAPUI5 while paring a value which I get from a model.
if (oCurrentQuestionModel.getProperty("/type") === "multiple choice")
How can I achieve this?
I need to format a string for parison purpose. Lets say we have Multiple Choice I want to convert it to multiplechoice So white spaces removed, any special characters removed and lowercase.
I need to do this in SAPUI5 while paring a value which I get from a model.
if (oCurrentQuestionModel.getProperty("/type") === "multiple choice")
How can I achieve this?
Share Improve this question edited May 16, 2017 at 7:46 loki asked May 16, 2017 at 7:29 lokiloki 6481 gold badge18 silver badges39 bronze badges 02 Answers
Reset to default 4You can do it as:
var str = "Multiple Choice";
var strLower = str.toLowerCase();
strLower.replace(/\s/g, '');
Working demo.
The Regex
\s
is the regex for "whitespace", and g
is the "global" flag, meaning match all \s
(whitespaces).
function cleaner(str) {
if (str) {
var strLower = str.toLowerCase();
return strLower.replace(/\W/g, '');
}
return false;
}
本文标签:
版权声明:本文标题:javascript - Remove spaces from a string, special characters and convert it to lowercase - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741978410a2408257.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论