shrug-l: label word-wrap
Jay Johnson
JohnsonJa at leoncountyfl.gov
Tue May 16 11:19:56 EDT 2006
Bret,
For a freebie solution, it is possible to use ArcGIS's "Label
Expression" function to insert line returns in the label. You could,
for instance, search the string and insert a vbnewline every place there
is a space character. The code below does this, as well as changing the
label into proper case (first letter of each word capitalized) and
properly capitalizing Scottish words (e.g. "MacBeth"). Just go to Layer
Properties/Labels/Expression, Click Advanced and paste the code.
Replace "[NAME]" with whatever field you are labeling on (THREE
replacements).
You could further modify this code to only break after X characters,
etc.
'******CODE
FOLLOWS****************************************************
' VERSION: Stack Text - USES [NAME] FIELD
' NAME: name_propercase_stacked.lxp
' ORIGINALNAME: TitleCase
' BY: Justin Kraemer
' BASED ON ProperCase by: Raine Lightner
' INPUTS: sString, your input
'
' RETURNS: Your formatted string.
'
' Now supports hyphenated words by
' capitalizing the first letter after
' each hyphen. "Mc" and "Mac" words are
' also now supported.
'
' MODIFIED BY JAY JOHNSON 6-20-04
' LEON COUNTY PUBLIC WORKS GIS
' ADDED CODE TO INSERT LINEBREAK AT "of" OR "("
' AND TO DEAL WITH THE CAPITALIZATION CORRECTLY
' AND TO STACK ALL TEXT AFTER A SPACE
'**************************************
Function TitleCase(sString)
Dim lTemp
Dim sTemp, sTemp2
Dim x
Dim HyphenExists
Dim LParenExists
Dim SpaceExists
Dim OfExists
Dim McExists
Dim MacExists
Dim HasAllCapsWord
Dim i
Dim iSpace
sString = LCase(sString) ' Set the entire string to lowercase
If Len(sString) Then
sTemp = Split(sString, " ") ' Split the string into individual words
lTemp = UBound(sTemp) ' Find the number of words in the array
sTemp2 = ""
For x = 0 To lTemp ' For each word in the array...
sTemp2 = sTemp2 & UCase(Left(sTemp(x), 1)) & Mid(sTemp(x), 2) & "
"
Next ' capitalize the first letter, and leave
the rest lowercase & add a space
TitleCase = Trim(sTemp2) ' Trim any excess spaces
sTemp = ""
sTemp2 = ""
HyphenExists = InStr(TitleCase, "-") ' Search for presence of a
hyphen
If HyphenExists Then ' If there is a hyphen,
then
sTemp = Left(TitleCase, HyphenExists) & UCase(Mid(TitleCase,
HyphenExists + 1, 1)) & Right(TitleCase, Len(TitleCase) - HyphenExists -
1) 'Capitalize the first letter after the hyphen
TitleCase = Trim(sTemp)
End If
'***Code inserted to deal with parenthetical expressions
LParenExists = InStr(TitleCase, "(") ' Search for presence of a
left parenthesis
If LParenExists Then ' If there is a hyphen,
then
sTemp = Left(TitleCase, LParenExists -1) & vbNewLine &
Mid(TitleCase, LParenExists, 1) & UCase(Mid(TitleCase, LParenExists + 1,
1)) & Right(TitleCase, Len(TitleCase) - LParenExists - 1) 'Capitalize
the first letter after the left parenthesis
TitleCase = Trim(sTemp)
End If
'***End of LParen code
'***Code inserted to stack text after every space***************
iSpace = 0
Do While iSpace = 0
SpaceExists = InStr(TitleCase, " ") ' Search for presence of a
Space
If SpaceExists Then ' If there is a Space, then
' sTemp = Left(TitleCase, SpaceExists -1) & vbNewLine &
Mid(TitleCase, SpaceExists, 1) & UCase(Mid(TitleCase, SpaceExists + 1,
1)) & Right(TitleCase, Len(TitleCase) - SpaceExists - 1) 'Capitalize the
first letter after the Space
sTemp = Left(TitleCase, SpaceExists -1) & vbNewLine &
UCase(Mid(TitleCase, SpaceExists + 1, 1)) & Right(TitleCase,
Len(TitleCase) - SpaceExists - 1) 'Remove the Space and Capitalize the
first letter after the Space
TitleCase = Trim(sTemp)
Else
iSpace= iSpace + 1
End If
Loop
'***End of Space code***************************************
'***Code inserted to break names containing OF onto two lines and to
not capitalize the "Of"
OfExists = InStr(TitleCase, " Of ") ' Search for presence of the
phrase "Of"
If OfExists Then ' If there is an "Of", then
sTemp = Left(TitleCase, OfExists) & vbNewLine & "of" &
Right(TitleCase, Len(TitleCase) - OfExists -2) 'Insert a line break left
of "Of" and don't capitalize the "Of"
TitleCase = Trim(sTemp)
End If
McExists = InStr(TitleCase, "Mc")
If McExists Then 'If there is an "Mc" in the name,
then
sTemp = ""
sTemp = Left(TitleCase, McExists + 1) & UCase(Mid(TitleCase,
McExists + 2, 1)) & Right(TitleCase, Len(TitleCase) - McExists - 2)
'Capitalize the first letter after
the "Mc"
TitleCase = Trim(sTemp) 'Trim any excess spaces
End If
MacExists = InStr(TitleCase, "Mac")
If MacExists Then 'If there is a "Mac" in the name,
then
sTemp = ""
sTemp = Left(TitleCase, MacExists + 2) & UCase(Mid(TitleCase,
MacExists + 3, 1)) & Right(TitleCase, Len(TitleCase) - MacExists - 3)
'Capitalize the first letter after
the "Mac"
TitleCase = Trim(sTemp) 'Trim any excess spaces
End If
Else
TitleCase = sString
End If
End Function
Function FindLabel ( [NAME] )
FindLabel = TitleCase([NAME])
End Function
'************CODE ENDS***********************************************
Jay Johnson
Leon County Public Works
Tallahassee/Leon County Interlocal GIS
(850) 606-1529
More information about the SHRUG-L
mailing list