Insert a line break after a specified number of characters

1887
4
Jump to solution
04-10-2012 03:29 PM
DavidThames1
New Contributor II
We use a FindLabel expression to retrieve characters from a number of attribute fields (up to 32). The characters correspond to a font which display as symbols on the map, e.g. ???C??? displays a Caravan Park symbol. The characters are concatenated into a single character string. There are no characters separating the symbols (e.g. a space). Where a feature has a lot of facilities (e.g. a major town), the resulting line of symbols can be rather long and look clumsy on the map.
We would like to use an expression to force a line break after a given number of characters (e.g. 6), so that the symbols are stacked in a neat pile near the feature they describe. We have tried using the ???Stack Label??? function in Maplex but have so far got inconsistent results.
We???d be grateful for any suggestions of a way to consistently force a line break after a specified number of characters.
[ATTACH=CONFIG]13404[/ATTACH]
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
Hi Richard ??? thanks for your response. I think your solution would work if the text came from a single field.
Unfortunately out text string is not retrieved from a single field (like [My_Field]), but built from many fields. We do it like this so we can control the colour of each character/symbol independently with tags around the field, e.g. FindLabel = "<CLR cyan='100'>" & [PoliceStation] & "</CLR>" & "<CLR magenta='100'>" & [CaravanPark] & "</CLR>"


I missed that.  It is still a basic set of if tests to build the string and determine if a vbnewline needs to be inserted with a counter.   I assume that if a field is white space it does not create a character in your string.  Something like the following should work (it may not be elegant, but it would be reliable for any myBreak value from 1 up with just more copy/paste and modifying each field name and color).  The code assumes that there are no Null field values.

Function FindLabel ( [PoliceStation], [CaravanPark], [Field3], [Field4], [Field5], [Field6], [Field7, [Field8]) ' etc. for all fields in your list   myStr = ""   myBreak = 6   i = 0   if [PoliceStation] > " " Then     i = 1     myStr = "<CLR cyan='100'>" & [PoliceStation] & "</CLR>"   End If   if [CaravanPark] > " " Then ' This begins the basic block to copy     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [CaravanPark] & "</CLR>   End If ' This ends the basic block to copy   if [Field3] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field3] & "</CLR>   End If   if [Field4] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field4] & "</CLR>   End If   if [Field5] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field5] & "</CLR>   End If   if [Field6] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field6] & "</CLR>   End If   if [Field7] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field7] & "</CLR>   End If   if [Field8] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field8] & "</CLR>   End If   'etc.   FindLabel = myStr End Function

View solution in original post

0 Kudos
4 Replies
RichardFairhurst
MVP Honored Contributor
We use a FindLabel expression to retrieve characters from a number of attribute fields (up to 32). The characters correspond to a font which display as symbols on the map, e.g. �??C�?� displays a Caravan Park symbol. The characters are concatenated into a single character string. There are no characters separating the symbols (e.g. a space). Where a feature has a lot of facilities (e.g. a major town), the resulting line of symbols can be rather long and look clumsy on the map.
We would like to use an expression to force a line break after a given number of characters (e.g. 6), so that the symbols are stacked in a neat pile near the feature they describe. We have tried using the �??Stack Label�?� function in Maplex but have so far got inconsistent results.
We�??d be grateful for any suggestions of a way to consistently force a line break after a specified number of characters.
[ATTACH=CONFIG]13404[/ATTACH]


This expression seems to work in VB Script to create a break for every 6 characters.  Just change the myBreak value to adjust for different character lengths:

Function FindLabel ( [My_Field] )
  myStr = ""
  myBreak = 6
  For i = 1 to Int(Len( [My_Field] )/myBreak)
    if i = 1 Then
      myStr = Left( [My_Field], myBreak)
    End If
    myStr = mystr  & vbNewLine & Mid([My_Field], i * myBreak + 1, myBreak)
  Next
  FindLabel = myStr
End Function
0 Kudos
DavidThames1
New Contributor II
Hi Richard �?? thanks for your response. I think your solution would work if the text came from a single field.
Unfortunately out text string is not retrieved from a single field (like [My_Field]), but built from many fields. We do it like this so we can control the colour of each character/symbol independently with tags around the field, e.g. FindLabel = "<CLR cyan='100'>" & [PoliceStation] & "</CLR>" & "<CLR magenta='100'>" & [CaravanPark] & "</CLR>"
0 Kudos
RichardFairhurst
MVP Honored Contributor
Hi Richard ??? thanks for your response. I think your solution would work if the text came from a single field.
Unfortunately out text string is not retrieved from a single field (like [My_Field]), but built from many fields. We do it like this so we can control the colour of each character/symbol independently with tags around the field, e.g. FindLabel = "<CLR cyan='100'>" & [PoliceStation] & "</CLR>" & "<CLR magenta='100'>" & [CaravanPark] & "</CLR>"


I missed that.  It is still a basic set of if tests to build the string and determine if a vbnewline needs to be inserted with a counter.   I assume that if a field is white space it does not create a character in your string.  Something like the following should work (it may not be elegant, but it would be reliable for any myBreak value from 1 up with just more copy/paste and modifying each field name and color).  The code assumes that there are no Null field values.

Function FindLabel ( [PoliceStation], [CaravanPark], [Field3], [Field4], [Field5], [Field6], [Field7, [Field8]) ' etc. for all fields in your list   myStr = ""   myBreak = 6   i = 0   if [PoliceStation] > " " Then     i = 1     myStr = "<CLR cyan='100'>" & [PoliceStation] & "</CLR>"   End If   if [CaravanPark] > " " Then ' This begins the basic block to copy     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [CaravanPark] & "</CLR>   End If ' This ends the basic block to copy   if [Field3] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field3] & "</CLR>   End If   if [Field4] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field4] & "</CLR>   End If   if [Field5] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field5] & "</CLR>   End If   if [Field6] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field6] & "</CLR>   End If   if [Field7] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field7] & "</CLR>   End If   if [Field8] > " " Then     if i = mybreak Then       myStr = myStr & vbnewline       i = 0     End If     i = i + 1     myStr = myStr & <CLR magenta='100'>" & [Field8] & "</CLR>   End If   'etc.   FindLabel = myStr End Function
0 Kudos
DavidThames1
New Contributor II
Worked a treat - thank you very much.

[ATTACH=CONFIG]13438[/ATTACH]
0 Kudos