Acad Independent Functions
Strings

Topics

Topics in this section:

Predicates

Comparison

Accessors, Searching, Matching

Conversion

Splitting and Joining

Formatting

Miscellaneous

Some of the functions accept symbols instead of strings. If the symbol evaluates to a string, then the symbol is changed destructively, that means no explicit SETQ is required.

Maybe those functions should have a distinguishable name?

Defined in the module STDSTR, the file STDSTR.LSP.

Naming Conventions

stringp has no std- prefix, all others should have.

Most of it are prefixed with std-str (C-like) or std-string- (Lisp-like)

C-like case-insensitive functions are prefixed with std-stri

C-like reverse operating functions (from the right) are prefixed with std-strr

Function Reference

Predicates

(STRINGP expr) ; is expr a string?

(STD-STRING-NOT-EMPTY-P expr) ; not empty string?

(STD-ISCHAR char) ; [a-zA-Z] or language specific special chars or ints?

(STD-ISDIGIT char) ; [0-9]

(STD-ISCONTROL char) ; not in DCL printable character?

(STD-ISUPPER char) ; uppercase char or int?

(STD-ISLOWER char) ; lowercase char or int?

Comparison

There exist according the Common Lisp standard case-sensitive and case-insensitive comparisons. As with EQ and EQUAL the shorter names are stronger on types. So far there are no optimized methods for this. Take care of possible locale differences!

At first the "stronger" comparisons: Case-Sensitive

(STD-STRING= s1 s2) ;

(STD-STRING/= s1 s2) ;

(STD-STRING< s1 s2) ;

(STD-STRING<= s1 s2) ;

(STD-STRING> s1 s2) ;

(STD-STRING>= s1 s2) ;

Now the "weaker" comparisons: Case-Insensitive

(STD-STRING-EQUAL s1 s2) ;

(STD-STRING-NOT-EQUAL s1 s2) ;

(STD-STRING-LESSP s1 s2) ;

(STD-STRING-NOT-LESSP s1 s2) ;

(STD-STRING-GREATERP s1 s2) ;

(STD-STRING-NOT-GREATERP s1 s2) ;

Accessors, Searching, Matching

(STD-STRING-ELT str i) ; i'th ascii int, zero based!

(STD-FIRSTCHAR str) ; the first char

(STD-LASTCHAR str) ; the last char

(STD-LASTCHARS n str) ; last n chars

(STD-STR-1 str) ; "string minus 1" without the last char

(STD-STR-N n str) ; string without the last n chars

(STD-STRPOS substr str) ; position of substr in str, 1-based

(STD-STRIPOS substr str ) ; case-insensitive

(STD-STRING-POSITION ichar str ) ; position of intchar in str, zero-based!

(STD-STRCMP substr str ) ; substring the first part of string?

(STD-STRICMP substr str ) ; case-insensitive

(STD-STRING-MISMATCH str1 str2) ; length of the longest common prefix

(STD-WCIMATCH str match) ; case-insensitive

(STD-STRCOUNT substr str ) ; counts substring in string

(STD-STRMEMBER match strlst) ; using wcmatch

(STD-STRIMEMBER match strlst) ; using std-wcimatch

(STD-STRLIST-MATCH match strlst) ; returns all matching elements

Conversion (some are destructive)

(STD-STRCASE str) ; also 8-bit chars

(STD-STRING-UPCASE 'str) ; also destructive

(STD-STRING-DOWNCASE 'str) ;

(STD-STRING-CAPITALIZE 'str) ;

(STD-CPTRANS str from-cp to-cp) ; codepage translation

Also under Lisp Specific:

(STD-SYMBOL-NAME sym) ; symbol->string conversion

(STD-TOSTR sym) ; accepts any expression

Replace

(STD-STRING-SUBST new old str) ; simple search/replace

(STD-STRCHG str old new) ; same as std-strchg

(STD-STRING-TRANSLATE old new str) ; replaces charbags, as unix tr

(STD-STRING-WC-REPLACE str pattern new options) ; wildcard replace

(STD-ENTAB str n) ; compress n spaces to tab

(STD-ENTAB8 str) ;

(STD-DETAB str n) ; expand tabs to n spaces

(STD-DETAB8 str) ;

Splitting and Joining (string <=> list)

Splitting or tokenizing splits a string into a list of substrings, bounded at special delimiters. Joining is the opposite, converting a list of strings into one string with a delimiter string in-between.

There are two general tokenizers:

The "soft" STD-STRTOK omits empty entries which is useful for removing unwanted whitespace and noise, and the "hard" STD-STRSPLIT keeps null tokens as "", which might be useful for reading comma-delimited lists.

Tokenizers:

(STD-STRTOK str delims) ; (std-strtok " ,1, 2" ", ") => ("1" "2")

(STD-STRSPLIT str delim) ; (std-strsplit ",1" ",") => ("" "1")

Complement:

(STD-STRJOIN strlst delim) ; ("1" "2") "/" => "1/2"

Helper funcs:

(STD-STRING->LIST str) ; "12" => (49 50)

(STD-LIST->STRING intlst) ; (49 50) => "12"

(STD-LIST->WSTRING intlst) ; "wide string" support, unicode

Abstractions:

(STD-STRING->STRLIST str delims) ; " 1 2" => ("1" "2")

(STD-STRLIST->STRING strlst delim) ; ("1" "2") "/" => "1/2"

(STD-CSSTRING->STRLIST str) ; ",,1,2" => ("1" "2")

(STD-STRLIST->CSSTRING strlst) ; ("1" "2") => "1,2"

(STD-DCLSTRING->STRLIST str) ; "1 2" => ("1" "2")

(STD-STRLIST->DCLSTRING strlst) ; ("1" "2") => "1 2"

Formatting (justify)

(STD-TRIM str) ; trims right and left whitespace

(STD-STRING-TRIM charbag str) ; trim right and left

(STD-STRING-RIGHT-TRIM charbag str)

(STD-STRING-LEFT-TRIM charbag str)

(STD-STRING-REMOVE-COMMENTS 'str) ; removes lisp like comments

(STD-STRING-LEFT-PAD-CHAR str len fill-char) ; fill string on the left side with char up to length n

(STD-STRING-RIGHT-PAD-CHAR str len fill-char) ; fill string on the right side with char up to length n

(STD-LPAD s len) ; left padding, cuts string or fills string leftwise with spaces

(STD-RPAD s len) ; right padding, cuts string or fills string rightwise with spaces

(STD-STRCENTER str len) ; fill with blanks right and left

Miscellaneous

(STD-STRING-SUBST new old str) ; simple search/replace

(STD-STRCHG str old new) ; same as std-strchg

(STD-STRING-TRANSLATE old new str) ; replaces charbags, as unix tr

(STD-ENTAB str n) ; " " => tab

(STD-ENTAB8 str) ;

(STD-DETAB str n) ; tab => " "

(STD-DETAB8 str) ;

(STD-RTOS num) ; convert to string with max. accuracy

(STD-MAKE-STRING n def) ; create str of n chars

Zero based - One based

Recently some low-level string functions appeared to be zero-based. These are STD-STRING-ELT and STD-STRING-POSITION.

Unicode support

Not unicode enabled AutoCAD systems cannot handle unicode characters at all. We support so far only STD-LIST->WSTRING which converts a list of integers, which might be larger than 255, to a string. Non unicode enabled systems will throw an error here.