Hi,
I somehow forgot how to trim a string.
str.trim() does not work.
Thank you in advanced,
Ariel
leading and trailing spaces: trim
Hi,
No trim function in Switch Javascript Object Model but it's pretty easy to get this result with a replace call:
HTH
Loic
No trim function in Switch Javascript Object Model but it's pretty easy to get this result with a replace call:
Code: Select all
var str = " foo ";
">"+str.replace(/(^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$)/g, "" )+"<" //>foo<
Loic
Thanks for sharing this. That is very helpful.loicaigon wrote:No trim function in Switch Javascript Object Model but it's pretty easy to get this result with a replace call:
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
ArielRauch
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
I agree with Gabriel - very helpful.
Thank you very much
Ariel
Thank you very much
Ariel
My pleasure. Be aware though that it will only remove trailing and leading "spaces". Something like "hey you" won't be considered with previous regular expression but I was sticking to the idea of trimming the string.
For the ones looking for a more global replacement like " he llo " to "hello", you may prefer to use :
For the ones looking for a more global replacement like " he llo " to "hello", you may prefer to use :
Code: Select all
str.replace (/[\s\uFEFF\xA0]+/g, "")- andrea mahoney
- Newbie
- Posts: 19
- Joined: Tue Jan 25, 2011 8:53 pm
You can use a Switch Variable to do this with norm or trim from the Variable options:
job.getVariableAsString("[Job.NameProper:Space=\"norm\"]");
job.getVariableAsString("[Job.NameProper:Space=\"norm\"]");