Function Definitions

 10  -  Text Strings

ascii ..... Returns the ASCII code for the first character of a string

(ascii "A")  returns 65
(ascii "CAT")  returns 67
(ascii "476.25")  returns 52 


chr ..... Returns a string which corresponds with the given ASCII code

(chr 65)  return "A"
(chr 67)  return "C"
(chr 97)  returns "a"
(chr 51)  returns "T"
(chr 34)  returns " (a double quotation mark)


strlen ..... Returns an integer representing the number of characters, spaces, etc. in a string

(strlen "25 books")  returns 8
(strlen "15 + 17")  returns 7
(strlen "")  returns 0


strcat ..... Concatenates (joins) two or more strings into one string

(strcat "Auto" "LISP")  returns "AutoLISP"
After (setq a "2.50" b "1.80")
(strcat a "," b)  returns "2.50,1.80" 


substr ..... Returns a substring of a given string, starting at a given character and of a given length.  The first argument is a string (the "source" of the substring).  The second argument is an integer indicating the character number in the source string where the substring will start.  The third argument is an integer which indicates the number of characters to include in the substring.  If the third argument is greater than the number of remaining characters, only the remaining characters are returned in the substring.  If the third argument is omitted, the remainder of the source string is included in the substring.

(substr "America" 2 5)  returns "meric"
(substr "Chicago" 6 4)  returns "go"
(substr "Chicago" 6)  returns "go"


strcase ..... Converts letters to upper or lower case.  All letters are converted to upper case when the second argument is either omitted or evaluates to nil.  All letters are converted to lower case if the second argument is non-nil.

(strcase "678 Pine Hollow Blvd.")  returns "678 PINE HOLLOW BLVD."
(strcase "678 Pine Hollow Blvd." 1)  returns "678 pine hollow blvd."


wcmatch ..... Tests for string matches by comparing a string with a pattern containing wild cards.  The wild cards are the same ones that can be used in response to the prompts of AutoCAD commands that handle named objects.  (See list of wild cards in AutoCAD User's Guide.)  Characters are case sensitive, and strings can be up to approx. 500 characters long.

(wcmatch "Greetings" "H*")  returns nil because the pattern requires that the string start with "H"
(wcmatch "Hello" "H*")  returns T because the wild card "*" in the pattern allows anything after the "H"
(wcmatch "hello" "H*")  returns nil because the "h" in the test string is lower case
(wcmatch "J7" "@#")  returns T because "J" is alphabetic, and "7" is numeric
(wcmatch "rice" "[lmnrv]ice") returns T because the "r" in "rice" matches one of the letters in the square brackets
(wcmatch "4,592" "*9*") returns T because the pattern allows a "9" anywhere in the test string
(wcmatch "123" "###,####") returns T because "123" is a 3 digit number (3 or 4 digit numbers are allowed)
(wcmatch "4,592" "*`,*) returns T because the pattern allows a comma anywhere in the test string (the reverse quote "`" causes the comma to be read literally rather than as a separator, as in previous example)
After (setq testme "Howdy" pattern "H*")
(wcmatch testme pattern)  returns T


Also see  acad_strlsort  under "9 - List manipulation"

HOME


Copyright © 1988, 1998 Ronald W. Leigh