ArcGIS Pro 1.4 Field calculator

04-09-2017 08:45 PM
New Contributor III

how do i extract the first character from another field, In desktop i would of used the Left([Field1],1)

0 Kudos
3 Replies
MVP Esteemed Contributor

Use this python expression:


Think Location
0 Kudos
MVP Legendary Contributor

But if there is the remotest change that you will have nulls in your table, then you have to go with a bit more pythonic magic which basically does a true/false test.  if the field called 'afield' is None (aka Null) then you take the slice to the right of the selection options.  If it contains text, then you take the slice to the left, which is the false part.

So in short the syntax is [ false section, true section][query]   or [0, 1][query] [False, True][query] useful functionality avoiding code blocks for simple yes/no questions

[!afield![0], None][!afield! is None]
MVP Esteemed Contributor

You can also handle the None/NULL issue using a Python conditional expression, which avoids the need for a code block with simple expressions and follows a classic ternary operator pattern:

None if None else !Field1![0]
0 Kudos