Author Topic: converting characters to Title Case  (Read 6080 times)

0 Members and 1 Guest are viewing this topic.

Humbertogo

  • Guest
converting characters to Title Case
« on: February 24, 2006, 04:47:41 AM »
How to converting  characters  to Title Case

"SAMPLE" ==> "Sample"

Thanks :roll:

hudster

  • Gator
  • Posts: 2848
Re: converting characters to Title Case
« Reply #1 on: February 24, 2006, 06:42:20 AM »
in mtext editor, right click, change chase. but I think that was too easy and not what your looking for
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: converting characters to Title Case
« Reply #2 on: February 24, 2006, 06:49:02 AM »
;;
;;  Tcase.lsp - Changes case of selected text, attdefs, attributes, dimension text,
;;               mtext, arcalignedtext and rtext.
;;                   
;;
;;  Copyright © 1999 by Autodesk, Inc.

Express Tools Folder ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: converting characters to Title Case
« Reply #3 on: February 24, 2006, 09:17:32 AM »
...Express Tools Folder ...

Funny, when I read your post I saw "Express Tools Fodder".

 :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Humbertogo

  • Guest
Re: converting characters to
« Reply #4 on: February 24, 2006, 09:40:55 AM »
Don't need to converting Mtext i need to convert a string to Title Case

zoltan

  • Guest
Re: converting characters to Title Case
« Reply #5 on: February 24, 2006, 09:55:05 AM »
I just whipped this up:
Code: [Select]
(Defun StrTitleCase ( STR )
 (StrCat (StrCase (SubStr STR 1 1)) (StrCase (SubStr STR 2) T) )
)

It only works for one word.

hold on..

zoltan

  • Guest
Re: converting characters to Title Case
« Reply #6 on: February 24, 2006, 10:13:31 AM »
Code: [Select]
(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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: converting characters to Title Case
« Reply #7 on: February 24, 2006, 10:17:18 AM »
This discussion includes a "proper" function that may, or may not be illuminating / intersting / useful.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

zoltan

  • Guest
Re: converting characters to Title Case
« Reply #8 on: February 24, 2006, 10:28:21 AM »
This discussion includes a "proper" function that may, or may not be illuminating / intersting / useful.

Hey wow, that function does EXACTLY what mine does.  Amazing!  :-D

Andrea

  • Water Moccasin
  • Posts: 2372
Re: converting characters to Title Case
« Reply #9 on: February 24, 2006, 10:37:51 AM »
Code: [Select]
(setq string "you ARE The King")
(setq string (strcat (strcase (substr string 1 1)) (strcase (substr string 2) 1)))
Keep smile...

zoltan

  • Guest
Re: converting characters to Title Case
« Reply #10 on: February 24, 2006, 10:50:03 AM »
_$ (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:

hudster

  • Gator
  • Posts: 2848
Re: converting characters to Title Case
« Reply #11 on: February 24, 2006, 10:56:57 AM »
This is Sentance case.

I'm glad everyone is reading the WHOLE thread here.  :roll:


Maybe they are checking their spelling instead. :-D
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

zoltan

  • Guest
Re: converting characters to Title Case
« Reply #12 on: February 24, 2006, 11:13:58 AM »
Yea yea... My spelling sucks!  :oops:

Andrea

  • Water Moccasin
  • Posts: 2372
Re: converting characters to Title Case
« Reply #13 on: February 24, 2006, 01:38:11 PM »
 :pissed:

I've used the Joe Burke routine..  http://www.theswamp.org/forum/index.php?topic=8817.0

Code: [Select]
(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))
Keep smile...

Humbertogo

  • Guest
Re: converting characters to Title Case
« Reply #14 on: February 25, 2006, 04:40:24 AM »
thanks