Convert Text Element to Proper Case

2225
2
07-15-2013 09:57 AM
deleted-user-VeC5jUIlNXtq
Occasional Contributor III
Hey Folks,

Quick question: through vb.net is there a way to say, loop through selected text elements (in layout view) and convert the text to proper case? "CLASS III WETLAND" becomes "Class III wetland" (ignore the roman numerals, I'm expecting to have to manually modify that...as it would likely become 'iii' anyways.

I was hoping for a quick ArcObjects solution or possible Python solution. I'm an amateur at programming, so bear with me (I have a better understanding of VB.NET, but I do know that Python might be the faster route, if something like this exists).

Thanks!
0 Kudos
2 Replies
LeoDonahue
Occasional Contributor III
0 Kudos
RichardFairhurst
MVP Honored Contributor
Your example is what I believe is called Sentence Case, not Proper Case/Title Case.  Proper Case (corrected for Roman Numerals) would have been "Class III Wetlands", not "Class III wetlands".

For Sentence Case to capitalize just the first word of a sentence you would normally just use in VB.Net:

' Split string based on periods
Dim s As String = "CLASS III WETLANDS.  CLASS IV WETLANDS."

Dim sentences As String() = s.Split(New Char() {"."c})

' Use For Each loop over sentences to change case
Dim sentence As String
s = ""
For Each sentence In sentences
    s = s & UCase(Left(LCase(sentence), 1)) & "."
Next
s.Replace("..", ".")

The output of string s would be:  "Class iii wetlands.  Class iv wetlands."

Of course, that does not work for sentences that include Roman numerals, the pronoun "I", proper names or sentences that trail off with "...".  If you want case sensitivity like you get when you use Word, that level of sophistication will not be achieved using simple coding techniques and is beyond the scope of what I could help you with.
0 Kudos