Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a planning cadastre dataset. It has the type of plan (DP, RP or SP) and then the plan number, thusly:

DP123456 RP1248590000 SP3855 etc...

I want to make a label in the expression builder in ArcGIS 10 which skips the first two characters and only has the plan number. In full, this is what I have done:

left([planlabel],2)&vbnewline&left([planlabel],len([planlabel]-2))&vbnewline& [lotnumber]

You can see here that I am making a stacked label which will put the type of plan on the first row (it is always the first two characters of [planlabel] and then the second row has the plan number, followed by [lotnumber] on the last line.

In Excel, string indexing of this sort is apparently achieved by CELL,len(CELL-2) and I was hoping the same would hold for VBscript in ArcGIS but apparently this is not the case.

Any clues?

Thanks,

Wil

share|improve this question

2 Answers 2

up vote 2 down vote accepted

This can be done very simply in Python, by selecting the Python parser and then ticking the advanced box. The code below does what you attempted to do in VBScript, using \n as a newline character and Python's powerful string indexing:

def FindLabel ( [planlabel], [lotnumber]  ):
   return [planlabel][:2] + '\n' + [planlabel][2:] + '\n' + [lotnumber]

To do this in VBScript the code block would be as follows, again ticking the advanced box:

Function FindLabel ( [planlabel], [lotnumber]  )
  FindLabel = left([planlabel],2) & vbnewline & mid([planlabel],3,len([planlabel])) & vbnewline & [lotnumber] 
End Function

This uses the mid function to take the 3 character to the end of the string, defined using the len() function which gives the length of the string. I hope you'll agree the python syntax is a lot cleaner, but both have the same result.

Edit:

For completeness, so that this answer can be used as a reference for people using Javascript, here is the same label function in Javascript, again tick the advanced box:

function FindLabel ( [planlabel], [lotnumber] )
{
  return [planlabel].substring(0,2) + '\n' +[planlabel].substring(2,[planlabel].length) + '\n' +  [lotnumber];
}
share|improve this answer

You could try

mid([planlabel],3,100)

and it will return as many characters as you have after the 2nd character (up to the 100th)

or, mid([planlabel],3,len([planlabel]))

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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