0 Members and 1 Guest are viewing this topic.
...Express Tools Folder ...
(Defun StrTitleCase ( STR ) (StrCat (StrCase (SubStr STR 1 1)) (StrCase (SubStr STR 2) T) ))
(Defun StrTitleCase ( STR ) (StrCat (StrCase (SubStr STR 1 1)) (StrCase (SubStr STR 2) T) ));;Splits a string into a list of strings based on a delimiter string(Defun StrSplt ( str del / s cnt lastdel return) (SetQ s str) (While s (SetQ cnt 1) (While (<= cnt (StrLen s)) (If (= (SubStr s cnt (StrLen del)) del) (ProgN (SetQ lastdel cnt) (SetQ cnt (1+ cnt)) ) (SetQ cnt (1+ cnt)) ) ) (If lastdel (ProgN (SetQ return (Cons (Substr s (+ lastdel (StrLen del))) return)) (SetQ s (SubStr s 1 (1- lastdel))) (SetQ lastdel nil) ) (SetQ return (cons s return) s nil ) ) ) return);;Returns a sentence string given a list of strings and;;an optional length(Defun Sentence ( lst len / cnt return) (SetQ cnt 0 return "" ) (Repeat (Cond (len) (T (Length lst))) (SetQ return (StrCat return (Nth cnt lst) " ")) (SetQ cnt (1+ cnt)) ) (SetQ return (VL-String-Trim " " return)) return)(Defun TitleCase ( STR lstLOWER lstUPPER / sWord lstSent ) (ForEach sWord (StrSplt STR " ") (Cond ((If lstLOWER (Member sWord lstLOWER ) nil ) (SetQ lstSent (Cons (StrCase sWord T) lstSent) ) ) ((If lstUPPER (Member sWord lstUPPER) nil ) (SetQ lstSent (Cons (StrCase sWord) lstSent) ) ) (T (SetQ lstSent (Cons (StrTitleCase sWord) lstSent) ) ) ) ) (Sentence (Reverse lstSent) nil))
This discussion includes a "proper" function that may, or may not be illuminating / intersting / useful.
(setq string "you ARE The King")(setq string (strcat (strcase (substr string 1 1)) (strcase (substr string 2) 1)))
This is Sentance case.I'm glad everyone is reading the WHOLE thread here.
(defun String2List (str pat / i j n lst) (cond ((/= (type str)(type pat) 'STR)) ((= str pat)'("")) (T (setq i 0 n (strlen pat)) (while (setq j (vl-string-search pat str i)) (setq lst (cons (substr str (1+ i)(- j i)) lst) i (+ j n) ) ) (reverse (cons (substr str (1+ i)) lst)) ) )) ;end (setq TL (string2list "yOu are tHE kING" " "))(setq 2w "")(foreach n TL (setq 1w (strcat (strcase (substr n 1 1))(strcase (substr n 2) 1))) (setq 2w (strcat 2w 1w " ")))(alert (vl-string-right-trim " " 2w))