Parsing Strings of Variable Length
Posted: Thu Oct 15, 2009 5:10 pm
In a related project to my previous post 'Time Conversion', I am trying to parse the "DialedNumber" field, which can range from 12 characters to 3 characters. I am using the LONG() function to determine the string length. Below is my TI code:
IF(LONG(DialedNumber)=12);
NumberDialed='(' | subst(DialedNumber,2,3) | ') ' | subst(DialedNumber,6,3) | ' - ' | subst(DialedNumber,9,4);
ELSE;
IF(LONG(DialedNumber)=8);
NumberDialed=subst(DialedNumber,2,3) | ' - ' | subst(DialedNumber,5,4);
ELSE;
NumberDialed=DialedNumber;
ENDIF;
I'm sure there's probably a better way to do this (when I evaluate the code, I get an error message stating the following:)
Line 8: END OR ENDIF statement missing.
I'm also sure that my mistake is something that is something simple that I'm overlooking.
If anybody has a spare minute that they can take a look at the code and let me know if they have any suggestions, I would appreciate that. Thank you!
IF(LONG(DialedNumber)=12);
NumberDialed='(' | subst(DialedNumber,2,3) | ') ' | subst(DialedNumber,6,3) | ' - ' | subst(DialedNumber,9,4);
ELSE;
IF(LONG(DialedNumber)=8);
NumberDialed=subst(DialedNumber,2,3) | ' - ' | subst(DialedNumber,5,4);
ELSE;
NumberDialed=DialedNumber;
ENDIF;
I'm sure there's probably a better way to do this (when I evaluate the code, I get an error message stating the following:)
Line 8: END OR ENDIF statement missing.
I'm also sure that my mistake is something that is something simple that I'm overlooking.
If anybody has a spare minute that they can take a look at the code and let me know if they have any suggestions, I would appreciate that. Thank you!