How can I replace this: " / " from a string.
For example: "one / another one" ----> "one/another one"
It just removes the spaces between the slash.. no the orher spaces.
Thanks.
How can I replace this: " / " from a string.
For example: "one / another one" ----> "one/another one"
It just removes the spaces between the slash.. no the orher spaces.
Thanks.
This regexp will strip out any runs of whitespaces around slashes, but keeps the slashes intact.
> "one / another one / yet some more / until the end".replace(/\s*\/\s*/g, '/')
"one/another one/yet some more/until the end"
If you need to keep e.g. ////
intact, use +
for the quantifier:
> "one / another one / yet some more / until the end (yet this //// remains)".replace(/\s+\/\s+/g, '/')
"one/another one/yet some more/until the end (yet this //// remains)"
You can do this:
console.log("one / another one".replace(/\ \/ /, '/'));
You did'nt specified the language; In my answer I will be using Python;
use -
string_name = string_name.replace(' / ','/')
(where string_name is name of variable in which you stored the actual string)
'replace()' is used here , in the first argument you provide what you want to replace and in the second argument you provide with what you want to replace