Replace part of string in multiple fields of multiple SHPs

10-21-2020 06:34 AM
Occasional Contributor III


I am working with ArcMap, if needed I can install PRO on the machine.

I have a folder with multiple SHP.

I have to modify part of the string  in multiple fields and for all my SHPs.  THE SAME replacement across all my fields and SHPs.

Tried already code block in single SHP, Model builder and python....all failed.


according to the example below: how do I change ALL "https" into "http" for both SHPs?


0 Kudos
1 Reply
MVP Esteemed Contributor

If you have tried code and it failed, it helps to share what you tried and the error message with traceback.  That way, people can make specific comments on what you tried.

In terms of the actual 'https' to 'http' replacement, that can be easily achieved using a Python string replacement:

>>> url = ""
>>> new_url = url.replace('https:', 'http:')
>>> new_url

Next, embed that code in an update cursor:

from arcpy import da

table = # path to shape file
fields = ["Link1", "Link2", "Link3"]

with da.UpdateCursor(table, fields) as cursor:
    for row in cursor:
        row = [s.replace('https:', 'http:') for s in row]