Extracting Characters To The Right of a Hyphen

605
4
Jump to solution
06-22-2021 11:18 AM
JD1016
by
Occasional Contributor II

Hello Community!

First time posting.

另一个后是否可以提取字符吗character such as a hyphen? For example, I would like to extract STMH4120 from STMH4870-STMH4120 and place in a new field.

Thank you.

JD

0Kudos
2 Solutions

Accepted Solutions
DavidPike
MVP Frequent Contributor
JoeBorgione
MVP Esteemed Contributor

That indicates that not all of your records follow that convention and it's choking on a value that does not. You might want to first make a selection where:

YourFieldName like "%-%"

That will get only those records that David's expression can calculate.

That should just about do it....

View solution in original post

4 Replies
DavidPike
MVP Frequent Contributor

sue, just use field calculator and python

Making simple field calculations—Help | ArcGIS Desktop

Calculate Field examples—Help | ArcGIS Desktop

!your_field_name!.split('-')[1]
JD1016
by
Occasional Contributor II

Hi David,

Python is enabled in Field Calculator, my new field is called DwnStrmMH and these new values will be based on splitting another fields value. I've entered!FacilityID!.split('-')[1]and an error message comes back (please see attached).

Thanks.

JD

0Kudos
JoeBorgione
MVP Esteemed Contributor

That indicates that not all of your records follow that convention and it's choking on a value that does not. You might want to first make a selection where:

YourFieldName like "%-%"

That will get only those records that David's expression can calculate.

That should just about do it....
JD1016
by
Occasional Contributor II

Thank you, Joe. That did it. And thank you David!

JD