Hi, I'm trying to delete characters following a certain word (<-this word is "LON") using the Calculate Field tool in ArcGIS Pro. Anyone has any ideas how to do this? I'm looking for a script that I can put in the "Comments = " block of the Calculate Field tool.
I have a large dataset (n=389) and each line has different characters following the word "LON". So, the below script won't work. I'm looking for an alternative!
Replace($feature.<field_name>, "<text_value>", "")
Solved! Go to Solution.
Using python then:
!FieldNAME!.split("LON")[0] +"LON"
Just replace FieldNAME with the name of the field in question
Using python then:
!FieldNAME!.split("LON")[0] +"LON"
Just replace FieldNAME with the name of the field in question
This worked! Thank you so much!!
No probs. Could you mark it as the solution so others can quickly find it?
Is there a way to remove characters that are in between so it doesn't remove the rest of the string?
So what that code is doing is searching for the word "LON", splitting the field into two separate parts using it and returning the first part, then I just re-added the word "Lon" back on at the end.
If you just wanted to remove "LON" then you could either do a straight replace:
!FieldNAME!.replace("LON","")
Or, if it's more nuanced than that, then you could add the two (or more) parts of the split back together:
!FieldNAME!.split("LON")[0] + !FieldNAME!.split("LON")[1]
Can you give some samples of the data to better show the problem?
Sounds like you have something like
"LON 123" and you want to replace the "123" part?
Hi!
You can replace or delete any words or part of the word by any of the following options:
1.
2.