Skip to main content
1-Visitor
July 6, 2022
Question

String replace not working

  • July 6, 2022
  • 2 replies
  • 3772 views

Hi all,

 

I am trying to replace '_' underscores from a given string, using the string.replace function,

SB_9732186_1-1657081844278.png

but I am not able to achieve this,

SB_9732186_2-1657081939199.png

can anyone tell me where I am going wrong.

 

 

Thanks,

Sujith

 

2 replies

17-Peridot
July 6, 2022

Sujith,

 

What version of ThingWorx are you on?  I'm in 9.0 and it seems to work for me:

 

nmilleson_0-1657082630754.png

 

1-Visitor
July 6, 2022

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,

SB_9732186_0-1657083873176.png

but in log I am not getting it.

SB_9732186_2-1657083970152.png

 

 

Thanks,

Sujith

17-Peridot
July 6, 2022

Sujith,

 

What happens if you try and run the replace right in the log statement?

 

logger.warn(Unique.replace(/_/g,''));
16-Pearl
August 4, 2022

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('_',''));