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;
}