Page 1 of 1

TM1 TI Scan Function

Posted: Wed May 20, 2020 8:08 am
by AlphaWay
Hi All,

Good day.

Could you ppl help me to separate country name from a string(column). Say i have 1000 rows in country column , each row has its code and country name with "-" separated. Some has single "-" & some has "-"*"-" like eg:1
Please see the following example:

Eg:1
001-1ab-ab15 - Singapore
or
Eg:2
123 - India

I would want to extract the 'Singapore' and 'India' from that string into variables to load in cube. How can I possibly do this in TM1?

Thanks in advance!

Re: TM1 TI Scan Function

Posted: Wed May 20, 2020 8:18 am
by declanr

Code: Select all

sFind = '- ';
nLong = Long ( vsString );
iPos = nLong - 1;
nFound = 0;
While ( iPos > 0 & nFound = 0 );
	sSub = SubString ( vsString, iPos, 2 );
	If ( sSub @= sFind );
		nFound = 1;
	Else;
		iPos = iPos - 1;
	EndIf;
End;

If ( nFound = 0 );
	LogOutput ( 'INFO', 'Could not find country in string: ' | vsString );
Else;
	sCountry = SubString ( vsString, iPos + 2, nLong - iPos - 1 );
EndIf;

Re: TM1 TI Scan Function

Posted: Wed May 20, 2020 10:05 am
by AlphaWay
Thank you so much Declan for inputs! Based on your code, i got the exact result and output looks good.