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: 
Not applicable

Removing multiple occurances of a substring

Hi Experts ,

I have a scenario where I am getting multiple substring inside a string , I need to reduce the multiple occurrence to 1st occurance .

eg :

Input:

'this test is a test string test '

Output:

'this test is a string'

I am using substringcount function but don't know how to move forward .

Regards,

Shantanu

1 Solution

Accepted Solutions
stigchel
Partner - Master
Partner - Master

And the qvw attached

View solution in original post

7 Replies
varshavig12
Specialist
Specialist

Why you want to do this ?

Like what is the objective behind this ?

Anil_Babu_Samineni

Can you provide more values which you have. I am expecting real data. So that, we will figure out. The reason i am asking this? Suppose, Sometimes we do have different size of values.

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Not applicable
Author

Hi All ,

I am concatenating 4-5 field values to form this string , 'test' coming multiple times does not make any sense . So need to reduce the final string to the first occurrence of the string 'test'.

Regards,

Shantanu

Anil_Babu_Samineni

We can do different different ways. In fact, We will help you by using your key words as i recommend in the before Reply.

1) Replace(SubField(GetFieldSelections(Output),1),',','')

[Script]:

LOAD Welcome, SubField(Welcome,' ') as Output Inline [

Welcome

'this test is a test string test '

];

Output:

Capture.PNG

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Not applicable
Author

Hi anil ,

Thanks for the reply , can you please break it down and explain the thought process behind your solution .

Regards,

Shantanu

stigchel
Partner - Master
Partner - Master

Where you are concatenating, can you concatenate distinctly? See this example for New:

Data:

Load * ,Rowno() as Row Inline [Text

'this test is a test string test'

'yet another test string test'

];

Tmp:

Load *,AutoNumber(Word,Row) as Id;

Load Row,SubField(Text,' ') as Word resident Data;

New:

Load Concat(DISTINCT Word,' ',Id) as NewText Resident Tmp Group by Row;

stigchel
Partner - Master
Partner - Master

And the qvw attached