COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: sunily on 13 Jul 2018 04:30:55 AM

Title: Find a string between two symbols
Post by: sunily on 13 Jul 2018 04:30:55 AM
Hi,

I know this is a noob question and might be asked few times in this forum.

I want to extract a string between two symbols.

For eg: A_B_C_D

I want to extract B from this. There might be less or more _ in string and length of A,B,C,D is not fixed.
Title: Re: Find a string between two symbols
Post by: BigChris on 13 Jul 2018 05:00:28 AM
For the sake of clarification, are you looking for the first _ and the character(s) between that and the next _ ?
Title: Re: Find a string between two symbols
Post by: sunily on 13 Jul 2018 05:22:31 AM
Yes Chris, you got it right.
Title: Re: Find a string between two symbols
Post by: sunily on 13 Jul 2018 05:51:39 AM
Looks like I got it:

substring_index(substr(zoneName, locate('_',zoneName)+1,locate('_',zoneName)-1),'_',1)

Please validate or suggest better way
Title: Re: Find a string between two symbols
Post by: sdf on 13 Jul 2018 08:09:27 PM
are you always gonna get the 3rd string?

is substring([zoneName],3,0)

an option?