I have a feature class with label expression in VB script. I do not have the skill to convert a VB script to a python script.
Here is the VBScript:-
Function FindLabel ( [DESCRIPTION] )
if (left( [name] ,4) = "ABCD") then
FindLabel =PCase( MID( [DESCRIPTION] , 19, 100))
else
FindLabel = PCase( [DESCRIPTION] )
end if
End Function
Function PCase(strInput)
Dim iPosition
Dim iSpace
Dim strOutput
iPosition = 1
Do While InStr(iPosition, strInput, " ", 1) <> 0
iSpace = InStr(iPosition, strInput, " ", 1)
strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
strOutput = strOutput & LCase(Mid(strInput, iPosition + 1, iSpace - iPosition))
iPosition = iSpace + 1
Loop
strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
strOutput = strOutput & LCase(Mid(strInput, iPosition + 1))
PCase = strOutput
End Function
I came up with following python code. But it did not work:-
def FindLabel([DESCRIPTION]):
if [name][:4]=='ABCD':
FindLabel = PCase( [DESCRIPTION][19:100] )
else:
FindLabel = PCase( [DESCRIPTION] )
def PCase(strInput):
iSpace=strInput.find(" ", beg=0, end=len(strInput))
iPosition=1
while iSpace!=0:
iSpace=strInput.find(" ", beg=0, end=len(strInput))
strOutput=strOutput+strInput[0:1].upper()
strOutput=strOutput+strInput[iPosition+1:iSpace-iPosition].lower()
iPosition=iSpace+1
strOutput=strOutput+strInput[iPosition:1].upper()
strOutput=strOutput+strInput[iPosition+1:].lower()
return strOutput