Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

replace whole string by matching part of it

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?

 

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

You may also use a regex to cover the whole case:

(row1.myColumn.replaceAll("^.*helloword.*$", "Hello World")).replaceAll("^.*polo-world.*$", "Polo-World")

Should work.

 

View solution in original post

7 Replies
fdenis
Master
Master

on tmap.
on the right side you can push … button on filter or on expression.
on Expression builder select String Handling function ereplace
it's what you are looking for.
StringHandling.EREPLACE(row1.col1,"helloworld","Hello-World")
Anonymous
Not applicable
Author

@fdenis, it doesn't work. I need to remove anything before and after the words "helloworld"

Anonymous
Not applicable
Author

@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"

Anonymous
Not applicable
Author

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"

TRF
Champion II
Champion II

You may also use a regex to cover the whole case:

(row1.myColumn.replaceAll("^.*helloword.*$", "Hello World")).replaceAll("^.*polo-world.*$", "Polo-World")

Should work.

 

Anonymous
Not applicable
Author

@TRF and @rhall Thanks a lot! Both work well and can use as solutions.

TRF
Champion II
Champion II

You're welcome