How can I remove leading\trailing zeroes ?
for eg: I have a order ID- 000023567 in a source file. So,In order to move only the 23567 portion of the order ID to the cube, what function or steps I can follow in TI Process to achieve the result? Also, the number of zeroes can vary for different order IDs.
Thanks in advance for the help.
Removing leading\trailing zeroes in TM1
- qml
- MVP
- Posts: 1096
- Joined: Mon Feb 01, 2010 1:01 pm
- OLAP Product: TM1 / Planning Analytics
- Version: 2.0.9 and all previous
- Excel Version: 2007 - 2016
- Location: London, UK, Europe
Re: Removing leading\trailing zeroes in TM1
First of all - this is the wrong subforum, but I'm sure an Admin will kindly move the thread.
Stripping off zeroes can be done in a few ways, but I would generally convert the string to a number and then back to a string again:
Stripping off zeroes can be done in a few ways, but I would generally convert the string to a number and then back to a string again:
Code: Select all
sShortOrderID = TRIM( STR( NUMBR( vLongOrderID ), 32, 0 ) );
Kamil Arendt
-
- MVP
- Posts: 1827
- Joined: Mon Dec 05, 2011 11:51 am
- OLAP Product: Cognos TM1
- Version: PA2.0 and most of the old ones
- Excel Version: All of em
- Location: Manchester, United Kingdom
- Contact:
Re: Removing leading\trailing zeroes in TM1
Sadly TM1 doesn't have a Replace function - if it did you could just replace 0 with blank.
For leading zeroes in a purely numeric string you can just convert to a number and then back to string NumberToString ( StringToNumber ( vRecord ) )
But that obviously doesn't work for trailing zeroes and can't be used if you have any string in the record.
The all encompassing option is to loop each character and delete the zeroes.
For leading zeroes in a purely numeric string you can just convert to a number and then back to string NumberToString ( StringToNumber ( vRecord ) )
But that obviously doesn't work for trailing zeroes and can't be used if you have any string in the record.
The all encompassing option is to loop each character and delete the zeroes.
Code: Select all
sReplace = '0';
sReplaceWith = '';
iCount = Long ( vRecord );
While ( iCount > 0 );
If ( SubSt ( vRecord, iCount, 1 ) @= sReplace );
vRecord = SubSt ( vRecord, 1, iCount - 1 ) | sRecplaceWith;
EndIf;
iCount = iCount - 1;
End;
Declan Rodger
-
- MVP
- Posts: 1827
- Joined: Mon Dec 05, 2011 11:51 am
- OLAP Product: Cognos TM1
- Version: PA2.0 and most of the old ones
- Excel Version: All of em
- Location: Manchester, United Kingdom
- Contact:
Re: Removing leading\trailing zeroes in TM1
Randomly popped into my head earlier that my previous code didn't factor in what comes after the changed character... something like below would be more useful should anyone see this in the future.
Surprised no one pulled me up on this.
Code: Select all
sSuffix = '';
sReplace = '0';
sReplaceWith = '';
iCount = Long ( vRecord );
While ( iCount > 0 );
If ( SubSt ( vRecord, iCount, 1 ) @= sReplace );
vRecord = SubSt ( vRecord, 1, iCount - 1 ) | sReplaceWith | sSuffix;
Else;
sSuffix = SubSt ( vRecord, iCount, 1 ) | sSuffix;
EndIf;
iCount = iCount - 1;
End;
Declan Rodger