7

I am labeling certain Oil & Gas areas by Operator in ArcMap 10, using this expression:

"" & [OPERATOR] & "" & vbNewline & "" & [UNIT_NAME] & ""

enter image description here

The only problem is that when the operator includes an ampersand (&), the label messes up because it's reading it as part of the expression, and ends up looking like it does in the screenshot below.

I know that in PHP (from my experience programming unrelated to GIS), there is a way to escape certain characters, but I haven't been able to find it in VBScript.

Screenshot: https://i.stack.imgur.com/gdKxB.png

1

1 Answer 1

8

You can replace them in your script with the syntax

Function FindLabel ([LABELFIELD])
  NewString = Replace([LABELFIELD],"&","&")  
  FindLabel = "<ITA>" & NewString & "</ITA>"
End Function
4
  • 1
    Ok so here's what I changed my expression to, but it's still not working: <br /> <br /> Function FindLabel ( [OPERATOR], [UNIT_NAME] ) NewString = Replace ([OPERATOR],"&","&amp;") FindLabel = "<FNT size='8'>" & [OPERATOR] & "</FNT>" & vbNewline & "<BOL>" & [UNIT_NAME] & "</BOL>" End Function'
    – denim_dan
    Jun 29, 2012 at 15:39
  • 2
    Because you have assigned the "replace" to a variable called "NewString", you have to replace [OPERATOR] in the findlabel portion to the variable: NewString.
    – SaultDon
    Jun 29, 2012 at 15:51
  • 2
    This script works for me Function FindLabel ( [MODIFIER1], [TYPE] ) NewString = Replace( [MODIFIER1] ,"&","&amp;") FindLabel = "<FNT size='8'>" & NewString & "</FNT>" & vbNewline & "<BOL>" & [TYPE] & "</BOL>" End Function As SaultDon as said
    – kenbuja
    Jun 29, 2012 at 15:55
  • 1
    You're welcome. Please mark the question as answered.
    – kenbuja
    Jun 29, 2012 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.