How to replace text in string field

Karthik B N
Tera Contributor

Hi,

I have a requirement to replace underscore (_) in a text field with -, how can I do this.

1 ACCEPTED SOLUTION

newhand
Mega Sage

@Karthik B N 

Try this.

 

 

 

var s = "sdfsdf_ddddd_dfdf"
s = s.replaceAll("_","-")
gs.info(s)

// replaceAll may not work with some browsers.. use the below code instead....

var s = "sdfsdf_ddddd_dfdf"
s = s.replace(new RegExp("_","g"),"-")
gs.info(s)

 

 

 

Please mark my answer as correct and helpful based on Impact.

View solution in original post

2 REPLIES 2

newhand
Mega Sage

@Karthik B N 

Try this.

 

 

 

var s = "sdfsdf_ddddd_dfdf"
s = s.replaceAll("_","-")
gs.info(s)

// replaceAll may not work with some browsers.. use the below code instead....

var s = "sdfsdf_ddddd_dfdf"
s = s.replace(new RegExp("_","g"),"-")
gs.info(s)

 

 

 

Please mark my answer as correct and helpful based on Impact.

newhand
Mega Sage

@Karthik B N 

I modified my first post ...read it one more time~~~ important!!

Please mark my answer as correct and helpful based on Impact.