Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I calculate a text value, the value of which is separated by a special character?

For example: dog | duck, I would like to keep the first value: dog
elephant | cat, I want to keep elephant.

The length of characters are different.

share|improve this question

Try using the .split Python function in the field calculator. If, for example, you have dog|cat, the .split("|") function splits the string by | into two parts ['dog', 'cat']. The [0] at the end of the function states that you want the first of the two items in the list. Finally, to be sure there are no remaining spaces in the rows, use .strip()

enter image description here

share|improve this answer
He should split on " | " (with spaces) instead of "|" right? – Erica Aug 30 '14 at 19:48
Good call @Erica, this will be sensitive to spaces if indeed there are any in the field. Otherwise there will be spaces left over. – Aaron Aug 30 '14 at 19:58
it would be safer to remove the spaces after the split. Like this : !field!.split("|")[0].strip() – radouxju Aug 30 '14 at 20:12
Thanks @radouxju, post edited to address your comments. – Aaron Aug 30 '14 at 20:21

Your Answer


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.