COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: wbarry123 on 28 Sep 2011 01:19:02 PM

Title: Parsing a string
Post by: wbarry123 on 28 Sep 2011 01:19:02 PM
I have a string like this:
12fda;565adf;adferfff;adsfsagf45af

I need to extract each part of the string (seperated by the semi-colon) into their own individual data item. 
Thank you in advance.
Title: Re: Parsing a string
Post by: blom0344 on 28 Sep 2011 01:28:09 PM
Export and import the data into the database using the semicolon as separator. On SQL server this can be done through the wizards alone. When importing the number of columns needed is generated on the fly. You can then add the table to the model as a source..
Title: Re: Parsing a string
Post by: wbarry123 on 28 Sep 2011 01:39:58 PM
I guess I was unclear.  This is what I am trying to do:
ID   Call Number                                      Call #1      Call #2    Call #3      Call #4   
1   12fda;565adf;adferfff;adsfsagf45af      12fda      565adf      adferfff      adsfsagf45af   

I have this data item (call Number) where the data in string is seperated by a semi-colon.  In report studio, I need to create new data Items (Call#1, Call#2...) where they extract the data between the semi-colons.      
Title: Re: Parsing a string
Post by: blom0344 on 28 Sep 2011 01:43:31 PM
No , I understand you perfectly   ;)
Reimporting the data into another table can do this for you as the semi-colon is used as data seperator
Title: Re: Parsing a string
Post by: johangel on 29 Sep 2011 12:26:09 PM
wbarry123, in onother live I used for this in Business Objects substring, lenght en position.
tomorrow at work I try to find the formula.
greetings,
Johan
Title: Re: Parsing a string
Post by: johangel on 29 Sep 2011 12:39:23 PM
Sorry my string was of an other format: "Txxx;Bxxx;Gxxx;Hxxx" I think you  can't use position and lenght.
Title: Re: Parsing a string
Post by: colt on 30 Sep 2011 01:56:48 AM
Assuming dataitem [call]='12fda;565adf;adferfff;adsfsagf45af'
then
[call#1]=SUBSTRING([call];1;POSITION(';';[call])-1)      (='12fda')
now we need to get the reststring without [call#1] 
[call#Rest1]=SUBSTRING([call];POSITION(';';[call])+1;character_length([call])-POSITION(';';[call]))      (=565adf;adferfff;adsfsagf45af')

Now you can go on parsing [call#Rest1] instead of [call] to get [call#2] and so on.