Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi. I have a set of strings like below.
"helloworldabc"
"o helloworld"
"helloworld+++++"
"helloworld + 3"
"helloworld10"
"polo-world"
"polo-world+"
"polo-world++++++"
"polo-world15"
I want to match all the strings that have substring "helloworld" and replace the whole string by Hello-World without having the numbers, alphabets, symbols before and after. And do the same by matching the strings that have "polo-world" and replace by "Polo-World" along with removing anything before and after polo-world. Can someone suggest a way to do on treplace or tmap?
You may also use a regex to cover the whole case:
(row1.myColumn.replaceAll("^.*helloword.*$", "Hello World")).replaceAll("^.*polo-world.*$", "Polo-World")
Should work.
@fdenis, it doesn't work. I need to remove anything before and after the words "helloworld"
@fdenis, I have to replace the whole string now. EReplace changed only "helloworld" to "Hello-World" but the strings "helloworld++++", "helloworld10", "ohelloworld" etc didn't lose their "+++", "10" and "o"
You need to use indexOf() and if the index is greater than -1, replace the whole String. So something like this....
row1.myColumn.indexOf("Hello World")>-1 ? "Hello World" : row1.myColumn
The above can be used practically anywhere and says "If Hello World appears anywhere in my column, set the value I am returning to "Hello World", otherwise return the value that came in the column"
You may also use a regex to cover the whole case:
(row1.myColumn.replaceAll("^.*helloword.*$", "Hello World")).replaceAll("^.*polo-world.*$", "Polo-World")
Should work.