Strings
Print("abc" & "def"); "abcdef"The concatenation operators will convert their arguments into strings, if necessary. For example:Print("abc" && "def"); "abc def"
Print("abc" & 123); "abc123" Print("5 + 3 =" && 5 + 3); "5 + 3 = 8"As you would expect, there are a number of functions that operate on strings. One of the most important of these is
StrLen
--a function that calculates the length of a string. For example:
Print(StrLen("abc")); 3 Print(StrLen("")); 0A common error is to attempt to use
Length
rather than StrLen
to determine the length of a string. Length
returns the number of bytes in a string rather than the number of characters (the numbers can be very different because of two-byte characters, string terminators, and ink inside a rich string).For example:
Print(StrLen("abc")); 3 Print(Length("abc")); 8 Print(Length("")); 2
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996