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))
(defun TitleCase (strSentence / intCount intItem lstCharacters lstCharacters2) (setq strSentence (strcase strSentence 'T) intCount 0) (repeat (length (setq lstCharacters (vl-string->list strSentence))) (setq intItem (nth intCount lstCharacters)) (if (and (or (= intCount 0) (= (nth (1- intCount) lstCharacters) 32) ) (> intItem 96) (< intItem 123) ) (setq intItem (- intItem 32)) ) (setq lstCharacters2 (cons intItem lstCharacters2) intCount (1+ intCount) ) ) (print (reverse lstCharacters2)) (vl-list->string (reverse lstCharacters2)))