TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Humbertogo on February 24, 2006, 04:47:41 AM
-
How to converting characters to Title Case
"SAMPLE" ==> "Sample"
Thanks :roll:
-
in mtext editor, right click, change chase. but I think that was too easy and not what your looking for
-
;;
;; Tcase.lsp - Changes case of selected text, attdefs, attributes, dimension text,
;; mtext, arcalignedtext and rtext.
;;
;;
;; Copyright © 1999 by Autodesk, Inc.
Express Tools Folder ...
-
...Express Tools Folder ...
Funny, when I read your post I saw "Express Tools Fodder".
:-D
-
Don't need to converting Mtext i need to convert a string to Title Case
-
I just whipped this up:
(Defun StrTitleCase ( STR )
(StrCat (StrCase (SubStr STR 1 1)) (StrCase (SubStr STR 2) T) )
)
It only works for one word.
hold on..
-
(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)
)
_$ (TitleCase "this is a test of how this works" '("a" "of") nil)
_1_$
"This Is a Test of How This Works"
It still needs to take into account punctuation, so words ending in punctuation will match words in the list. And I guess the first word should always be caps, even if it is in the lower case list.
You can tell I have nothing to do at work today.
-
This discussion (http://www.theswamp.org/forum/index.php?topic=2953.msg37000#msg37000) includes a "proper" function that may, or may not be illuminating / intersting / useful.
-
This discussion (http://www.theswamp.org/forum/index.php?topic=2953.msg37000#msg37000) includes a "proper" function that may, or may not be illuminating / intersting / useful.
Hey wow, that function does EXACTLY what mine does. Amazing! :-D
-
(setq string "you ARE The King")
(setq string (strcat (strcase (substr string 1 1)) (strcase (substr string 2) 1)))
-
_$ (setq string "you ARE The King")
"you ARE The King"
_$ (setq string (strcat (strcase (substr string 1 1)) (strcase (substr string 2) 1)))
"You are the king"
_$
Title Case is Every Word in the Sentance, Except For a Few
This is Sentance case.
I'm glad everyone is reading the WHOLE thread here. :roll:
-
This is Sentance case.
I'm glad everyone is reading the WHOLE thread here. :roll:
Maybe they are checking their spelling instead. :-D
-
Yea yea... My spelling sucks! :oops:
-
:pissed:
I've used the Joe Burke routine.. http://www.theswamp.org/forum/index.php?topic=8817.0
(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))
-
thanks
-
Maybe
(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))
)