11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsWRITE $ASCII("W")The following example returns 960, the decimal equivalent for the Unicode character "pi".WRITE $ASCII($CHAR(959+1))The following example returns 84, the decimal equivalent of the ASCII value for the firstcharacter in the variable Z.SET Z="TEST"WRITE $ASCII(Z)The following example returns 83, the decimal equivalent of the ASCII value for the thirdcharacter in the variable Z.SET Z="TEST"WRITE $ASCII(Z,3)The following example returns a -1 because the second argument specifies a position greaterthan the number of characters in the string.SET Z="TEST"WRITE $ASCII(Z,5)The following example uses $ASCII in a FOR loop to convert all of the characters in variablex to their ASCII decimal equivalents. The $ASCII reference includes the position parameter,which is updated for each execution of the loop. When position reaches a number that isgreater than the number of characters in x, $ASCII returns a value of -1, which terminatesthe loop.SET x="abcdefghijklmnopqrstuvwxyz"FOR i=1:1 {QUIT:$ASCII(x,i)=-1WRITE !,$ASCII(x,i)}QUITThe following example generates a simple checksum for the string X. When $CHAR(CS) isconcatenated with the string, the checksum of the new string is always zero. Therefore, validationis simplified.CXSUMSET x="Now is the time for all good men to come to the aid of their party"SET CS=0FOR i=1:1:$LENGTH(x) {SET CS=CS+$ASCII(x,i)WRITE !,"Checksum is:",CS}SET CS=128-CS#128WRITE !,"Final checksum is:",CSThe following example converts a lowercase or mixed-case alphabetic string to all uppercase.180 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!