Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hi all,
I am trying to replace '_' underscores from a given string, using the string.replace function,
but I am not able to achieve this,
can anyone tell me where I am going wrong.
Thanks,
Sujith
Sujith,
What version of ThingWorx are you on? I'm in 9.0 and it seems to work for me:
Hi @nmilleson ,
I am using the latest build available on the cloud, I guess it is 9.2
In output even I am getting the desired result,
but in log I am not getting it.
Thanks,
Sujith
Sujith,
What happens if you try and run the replace right in the log statement?
logger.warn(Unique.replace(/_/g,''));
Hi @nmilleson ,
I did this:
and in the logs I got this:
I am also sending the variable UniqueID to another service, in the other service also the value contains '_':
Thanks,
Sujith
Sujith,
I have tried this and working fine. Could you please try like :arraydata[2].replace('_' , '')
Hi all,
Anyone has a solution for this?
Or do I raise a Case on eSupport?
Thanks,
Sujith
Hello,
you can replace another part of the string and see how it reacts?
like :arraydata[2].replace('IOTMH' , 'removed'));
Are you using the correct declaration of var/let? (even if this should have no affect on the logger)
If you can always remove the last character of the string, try "slice".
like :arraydata[2].slice(0, -1)
Best regards
Marc
What Marc wrote below is a very good solution.
There's a very slim chance that the code you shown us is not really the code that executed (by mistake?)
Are you 100% sure that the logger statement you see is generated by the code you've shown to us?
Otherwise, can you please send me the whole content of your service please in a PM?
This is clearly a topic for a Support Case, but I'm really curious to see the cause of this issue, as it should not happen.
Also write back the full version of ThingWorx you're using: 9.2.?
hi SB_9732186
below code worked fine on TW 9.3.2. Can you try on your TW instance?
---------------------------------------------------
var test = 'IOTMH22G022420_';
var result = test.replace('_','');
logger.warn("replace test : " + test.replace('_',''));