All the Vector Manipulation FunctionsVector_Manipulation_Functions treat the characters of strings and the digits of integers as if they were the elements of a vector.  Thus, you can use these same functions and operators to do a wide range of string processing operations, useful for cryptographic and other applications.  Note that strings are entered on the expression entry line enclosed in double quotes, but they are displayed in the algebra window worksheet without the double quotes.


In particular, the SUB subscript operator can be used to extract the characters of strings or the digits of integers.  For example,

"Derive" SUB 3

simplifies to string "r",

"Derive" SUB [1, 2, 6, 3]

simplifies to the string "Deer", and

123456789 SUB [1, 3, 5, -3, -1]

simplifies to the integer 13579.


Also, the DIM function can be used to determine the length of strings or the number of digits of integers.  For example,

DIM("Derive")

simplifies to 6, and

DIM(123456789)

simplifies to 9.


Also, the vector manipulation functions work on strings and integers as expected.  For example,

REVERSE(1234567890)

simplifies to the integer 987654321,

APPEND("a", "b", "c", 3)

simplifies to the string "abc3", and

DELETE("Derive", 2)

simplifies to the string "Drive".  Note that these can also accept negative indices to specify characters from the right end of a string.  For example,

DELETE("Derive", -5)

also simplifies to "Drive".


Similarly, the POSITION function can be used to search for a string in a string or in the digits of an integer.  For example, after taking a few seconds

POSITION("0000", FLOOR(10^15000*pi))

simplifies to the position of the first occurrence of four 0s in the decimal expansion of ð.


Use the STRING function to convert expressions to strings.  If u is a variable, STRING(u) simplifies to the string having the same name as u, but enclosed in double quotes.  If u is a number, STRING(u) simplifies to the string having the same digits as u, but enclosed in double quotes.  For example,

STRING(123456789)

simplifies to the string "123456789".  Note that the digits representing u are determined by the current output radix base set by the Options > Mode Settings > Output command3L4YH.


If u is a function composition, STRING(u) simplifies to a vector consisting of the string variable corresponding to the expression's top-level function or operator, followed by the function's arguments or operator's operands.  Note that the arguments and operands are not converted to strings.  For example,

STRING(x+y-z)

simplifies to ["+", x, y, -z], and

STRING(COS(x^2))

simplifies to ["COS", x^2].  The STRING function distributes over the elements of vectors and sets.


Use the NAME_TO_CODES function to convert a string or integer to a vector of ASCII codes for the characters in the string or the digits in the integer.  For example,

NAME_TO_CODES("Exact")

simplifies to [69, 120, 97, 99, 116].


Use the CODES_TO_NAME function to convert a vector of ASCII codes to the corresponding string or integer.  For example,

CODES_TO_NAME([69, 120, 97, 99, 116])

simplifies to the string "Exact", and

CODES_TO_NAME([45, 52, 49])

simplifies to the integer -41.  To generate a 16 by 16 matrix showing the character corresponding to each ASCII code, simplify the expression

VECTOR(VECTOR(CODES_TO_NAME(j + 16·i), i, 0, 15), j, 0, 15)

Note that strings containing the ASCII codes 0, 10, 13, and 34 are not allowed.


Other Vectors and MatricesVectors_and_Matrices topics

Created with the Personal Edition of HelpNDoc: Easy to use tool to create HTML Help files and Help web sites