How do I replace the first character of a string using calculate field in ArcGIS Pro?

2498
6
Jump to solution
07-28-2020 09:25 AM
JoeLivoti
New Contributor III

Pretty simple question I'm sure for the Python people out there. I have a field, FACILITY ID, that is populated as string values as 00001,00002, 00003, and so on. All values in the field are 5 characters long. I want to change the first number in to a 1 so the values of the field look like 10001, 10002, 10003, etc. I'm pretty sure i should use the .replace(), but I cannot format it correctly. Any advice would be very welcome. Thank you.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor
"1" + !YourField![1:]

python parser and YourField is the field that contains the original.

It is best to do calculations in a new field in case things go real bad.

You can copy them back into the original later


... sort of retired...

View solution in original post

6 Replies
DanPatterson
MVP Esteemed Contributor
"1" + !YourField![1:]

python parser and YourField is the field that contains the original.

It is best to do calculations in a new field in case things go real bad.

You can copy them back into the original later


... sort of retired...
JoeLivoti
New Contributor III

Dan,

Thank you that worked perfect. How would I augment that to change a different value in the string, say the second value to a 5? Again thank you!!!!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Although you asked a follow-up question, Dan addressed your first question.  Please mark his response as Correct to close out the question.

0 Kudos
DanPatterson
MVP Esteemed Contributor
"15" + !YourField![2:]

or if you just mean the 2nd value, leaving the first along

!YourField![:1] + "5" +!YourField![2:]

... sort of retired...
JoeLivoti
New Contributor III

Thank you Dan!! The second one was exactly what i needed!

0 Kudos
DanPatterson
MVP Esteemed Contributor

no problem


... sort of retired...
0 Kudos