Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
Make your voice heard! Participate in the 2020 Wisdom of Crowds® Survey. BEGIN SURVEY
Partner
Partner

Remove last substring from a string

Hi there, I have a field (called GROUP) containing multiple strings like this one:

Group1/Group2/Group3/Group4/Group5

and so on.

I don't always have the same number of substrings (divided by the '/'), sometimes there are more than 5 and sometimes less than 5.

I'd like to remove from these strings the last subfield, intependently of the number of substrings.

 

Has anyone any clue about how could I get this done?

1 Solution

Accepted Solutions
Highlighted
atoz1158
Contributor II

Re: Remove last substring from a string

Hi

As long as you have at least two substrings this should work for you

Left(GROUP ,Index(GROUP,'/',SubStringCount(GROUP,'/'))-1)

Regards

Adrian

View solution in original post

4 Replies
Highlighted
Partner
Partner

Re: Remove last substring from a string

use the formla: =SubField('Group1/Group2/Group3/Group4/Group5','/',-1)
it retreives the last subfield after the defined character from right (defining -1)

instead of hardcoded text use your data field

Highlighted
atoz1158
Contributor II

Re: Remove last substring from a string

Hi

As long as you have at least two substrings this should work for you

Left(GROUP ,Index(GROUP,'/',SubStringCount(GROUP,'/'))-1)

Regards

Adrian

View solution in original post

Highlighted
Partner
Partner

Re: Remove last substring from a string

Thanks, but that's not what I'm looking for, I wanted to keep the rest of the string, not the last one.

 

 

Highlighted
Partner
Partner

Re: Remove last substring from a string

Thank you, it worked perfectly!

I was assuming it had to do with the Index function.