upper to proper case in brackets

482
2
10-30-2011 05:42 PM
PierreKurth
New Contributor II
Hi there,

I have a name field in the database in capital letters. To label them in proper cases I use a label expression 'upper to proper case' no worries. 🙂

But when it comes to a name within brackets it does not work any more.

E.g. name in field: WARRAL (HAWKESBURY) ISLAND -> Warral (hawkesbury) Island.

Any idea how to fix that middle name?

Thanks a lot.

Pierre
Tags (2)
0 Kudos
2 Replies
SamuelTroth
New Contributor III
I'm assuming your label expression is something similar to this:

Function FindLabel ( [NAME] )
FindLabel = UCase(Left([NAME],1)) & LCase(Right([NAME], Len([NAME]) -1))
End Function


This expression will treat the bracket as the first character of your word, thus producing your observed result. Please use the following modified expression to overcome this.

function mcase(s)
  for each word in Split(s)
    if (left(word,1)="(" or left(word,1)="[" or left(word,1)="{") then
      mcase = mcase + " " + ucase(left(word,2)) + lcase(right(word,len(word)-2))
    else
      mcase = mcase + " " + ucase(left(word,1)) + lcase(right(word,len(word)-1))
    end if
  next
end function

Function FindLabel ( [Test]  )
  FindLabel = mcase( [Test] )
End Function


Sam
Esri
0 Kudos
PierreKurth
New Contributor II
Thank you Sam,

you are a legend. It is working perfectly.

Pierre
0 Kudos