Page 1 of 1

Parsing Strings of Variable Length

Posted: Thu Oct 15, 2009 5:10 pm
by shinymcshires
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!

Re: Parsing Strings of Variable Length

Posted: Thu Oct 15, 2009 5:28 pm
by Alan Kirk
shinymcshires wrote: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!
Try

Code: Select all

IF(LONG(DialedNumber)=12);
   NumberDialed='(' | subst(DialedNumber,2,3) | ') ' | subst(DialedNumber,6,3) | ' - ' | subst(DialedNumber,9,4);
ELSEIF(LONG(DialedNumber)=8);
   NumberDialed=subst(DialedNumber,2,3) | ' - ' | subst(DialedNumber,5,4);
ELSE;
  NumberDialed=DialedNumber;
ENDIF;

Re: Parsing Strings of Variable Length

Posted: Thu Oct 15, 2009 5:40 pm
by shinymcshires
Alan-

Looks like I owe you two lunches. My gratitude for your quick and accurate responses! That worked perfectly! Thank you!