I'm using field calculator in ArcGIS Desktop 10.2.1.

I have field1 which has a values of "A_B" (example). I created two fields out of this, values to the left of the underscore go in fielda and to the right of the underscore go in fieldb. I used the code below in field calculator to separate them out into two fields.

fielda =


fieldb =


I now have field1 with values of A_B_C_D. I need to separate the A_B_C_D into four separate fields using field calculator. fielda = A, fieldb = B, fieldc = C and so on. I'm not sure how to go about this. I basically need to parse the values by the underscore.


Python's split() returns a list object (an array), so if you use split("_") on "A_B_C_D" you get an array where you can access every Letter by its index. The underscore acts as an separation character in this case, and parsing character separated lists is one of the most common uses of the split() function









Appendix: The index [-1] means counting the index of the array backwards. So '-1' refers to the last element in the list, '-2' to the second last, '-3' to the third last and so on.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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