COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: elroy on 01 Jun 2011 10:16:34 AM

Title: Substring
Post by: elroy on 01 Jun 2011 10:16:34 AM
Hi all,
I have following issue:

I would like to get the abcd.xls from this string: /abc/def/ghijk/l/abcd.xls.

My idea:

substring('/abc/def/ghijk/l/abcd.xls', position('/', '/abc/def/ghijk/l/abcd.xls')+1, character_length('/abc/def/ghijk/l/abcd.xls'))

Unfortunately thats not correct because the function position returns the first position where the stated character is matched but I need the position of the last character (/).

Can anybody help?

Thanks and regards,
elroy
Title: Re: Substring
Post by: blom0344 on 01 Jun 2011 10:40:09 AM
Use the dot as reference point, cause it occurs only once in the entire string:

substring([dataitem],position('.',[dataitem])-4,100)

could be -5   ;D
Title: Re: Substring
Post by: elroy on 03 Jun 2011 01:17:23 AM
Mhh. The lenght of the filename and path are not fix. That's the problem..
Any other ideas?
Title: Re: Substring
Post by: blom0344 on 03 Jun 2011 03:19:56 AM
Are you on SQL server and can you use RDBMS type functions? Then it would be a matter of 1/ reversing the string with  'reverse' function, then 2/ taking the right part out of it and then 3/ reversing the resulting part again:

reverse(substring(reverse([data_item]),1,position('/',[data_item])))
Title: Re: Substring
Post by: elroy on 03 Jun 2011 03:38:53 AM
It works!
Many thanks :)
Title: Re: Substring
Post by: DALSOM on 28 Mar 2012 09:48:03 AM
Hi,
I want to do above, but, in an text expression, with a parameter text variable!!! :o