IN ArcGIS, what is the vbscript in the label expression box to build a label which has the outcome that if the string is over 50 characters long then the label should be formatted over 2 lines.
This is doable using the VBS label parser in ArcGIS, although recommended you start looking at using the Python parser as VBA/VBS is being phased out of ArcGIS Products.
In the Label Expression dialog check the Advanced box, and then paste the code below. Change
[Description] to the fieldname you are wanting to label.
If you just want to split the text after the 50th character you can use the following, however it may split mid-word and ignores whether the second line is longer than 50 characters also.
Function FindLabel ([Description]) If len([Description]) <= 50 Then FindLabel = [Description] Else FindLabel = left([Description], 50) & vbNewLine & mid([Description], 50) End If End Function
The following splits the label every 50 characters, at the nearest space (so doesn't split words), and splits additional lines if they are also longer than 50 characters.
Function FindLabel ([Description]) If len([Description]) <= 50 Then FindLabel = [Description] Else newString = "" subString = "" a = Split([Description]) For Each x in a If subString = "" Then subString = x Else lenSubString = len(subString & " " & x) If lenSubString > 50 Then If newString = "" Then newString = subString subString = "" Else newLine = True newString = newString & vbNewLine & subString subString = "" End If Else newLine = False subString = subString & " " & x End If End If Next FindLabel = newString End If End Function
This is why you want Python:
def FindLabel ( [TEXT]): t= [TEXT] return '%s\n%s' %(t[:50],t[50:])