Page 1 of 1

Delete characters from String

Posted: Mon Jun 07, 2010 7:38 pm
by ExApplix
In Turbo Integrator, I need to delete specific character from a String.

For example if my string is 100.200.12345 or 12.123.12345

then I would like to get rid of . (DOT) from the srings and it should look like as: 10020012345 or 1212312345

Please note that . (DOT) may appear after any number of characters.

I tired to use the DELET() and SCAN() but its not making sense to me.

Can someone please help!

Thanks!

Re: Delete characters from String

Posted: Mon Jun 07, 2010 8:30 pm
by rkaif
You may use WHILE loop to get rid of . (DOT)

See this code:

Code: Select all

iClean = 0;
WHILE ( iClean <> 1 );
	iPos = SCAN ( '.', dimVariable );
	IF ( iPos <> 0 );
		dimVariable  = DELET (dimVariable , iPos, 1 );
	ELSE;
		iClean = 1;
	ENDIF;
END;

#Test
ASCIIOutput(fileName, dimVariable);
Hope it helps!

Re: Delete characters from String

Posted: Wed Jun 09, 2010 8:15 am
by asvlad
It is actual for tabs (Prolog, Metadata, Data, Epilog) of TI, But if i should create variable with formula?

Re: Delete characters from String

Posted: Wed Jun 09, 2010 10:19 am
by jstrygner
Do you mean in Rules?

Loop in TI is great, as it is universal - you may have as many dots inside as you want - it will just work.
If you want to do it via Rules then it is not that elegant, but you can do it if there is a known maximum of dots (e.g. not more than 2).

In such a case you can create a rule like in my example below (what I actually did is I wrote a rule for tekst2 that takes rid of first dot in tekst1, then if you have a maximum of two dots you add a tekst3 that does the same with tekst2, as we can see you can easily expand it in case of larger amount of dots).

If you want, you can try to type it in one rule but then it gets even more non-elegant.

The rule is like this (I used attributes cube for this example):

Code: Select all

['tekst2']=S:
  SUBST(
    DB('}ElementAttributes_aa',!aa,'tekst1'),
    1,
    SCAN('.', DB('}ElementAttributes_aa',!aa,'tekst1'))-1)
  |
  SUBST(
    DB('}ElementAttributes_aa',!aa,'tekst1'),
    SCAN('.', DB('}ElementAttributes_aa',!aa,'tekst1'))+1,
    LONG(DB('}ElementAttributes_aa',!aa,'tekst1')));

['tekst3']=S:
  SUBST(
    DB('}ElementAttributes_aa',!aa,'tekst2'),
    1,
    SCAN('.', DB('}ElementAttributes_aa',!aa,'tekst2'))-1)
  |
  SUBST(
    DB('}ElementAttributes_aa',!aa,'tekst2'),
    SCAN('.', DB('}ElementAttributes_aa',!aa,'tekst2'))+1,
    LONG(DB('}ElementAttributes_aa',!aa,'tekst2')));
As you can see in the picture below, it works independently of where the dots are (elements a and b), it does not matter if there are less dots (elements c and d), if the dots are at the beginning or end of a string (element e) but in my case dots remain if there are more than two of them (element f).

HTH