replace alphabet with Arcpy in ArcMap

573
2
01-28-2022 11:59 PM
DasheEbra
Occasional Contributor
Dears I am trying to replace text in a field, I want to rematch English alphabet into Arabic alphabet like (a = ش, d = ي, s = س, etc...). I wrote a test script for 2 characters and run it in ArcMap 10.8 python window, it doesn't works well as it is work with English alphabet:
Data
 
Moelsaket_1-1643442991157.png

 here's my script:

-----------------------------------------------------------------------------------------------------------------------------

###script for arabic
fc = r"C:/New File Geodatabase.gdb/an3"
cursor = arcpy.da.UpdateCursor(fc, ["name1"])
for row in cursor:
      if "a" in row[0]:
            row[0] = row[0].encode('utf8').replace("a", "ض")
      if "s" in row[0]:
            row[0] = row[0].encode('utf8').replace("s", "س")
      cursor.updateRow(row)

dears i'm trying to replace text in field, i want to rematch English alphabet to Arabic alphabet like (a = ش, d = ي, s = س, etc...). I wrote a test script for 2 characters and run it in ArcMap 10.8 python window, it doesn't works well as it is work with English alphabet: here's my script: my data enter image description here

###script for arabic
fc = r"C:/New File Geodatabase.gdb/an3"
cursor = arcpy.da.UpdateCursor(fc, ["name1"])
for row in cursor:
      if "a" in row[0]:
            row[0] = row[0].encode('utf8').replace("a", "ض")
      if "s" in row[0]:
            row[0] = row[0].encode('utf8').replace("s", "س")
      cursor.updateRow(row)

Output/result 

Moelsaket_2-1643443063757.png

-----------------------------------------------------------------------------------------------------------------------------

test script with English alphabet instead of Arabic on the same data:

fc = r"C:/New File Geodatabase.gdb/an3"
cursor = arcpy.da.UpdateCursor(fc, ["name1"])
for row in cursor:
      if "a" in row[0]:
         row[0] = row[0].encode('utf').replace("a", "Q")
      if "s" in row[0]:
         row[0] = row[0].encode('utf').replace("s", "H")
      cursor.updateRow(row)

 Output:

Moelsaket_3-1643443130062.png

it works fine with all characters in all cells.

-----------------------------------------------------------------------------------------------------------------------------

 

Tags (1)
0 Kudos
2 Replies
JayantaPoddar
MVP Esteemed Contributor

In Field Calculator, I used VB Script Parser with a similar expression.

Replace(Replace(Replace( [SplitF],"a","ش " ), "d","ي"), "s","س")

The result looks like this

JayantaPoddar_0-1643453340733.png

Is the above output correct? 

 



Think Location
0 Kudos
RobertBorchert
Frequent Contributor III

I did not do this for a language but as a spell check.

What I would suggest is creating a look up table with the English Character in one column and the Arabic character in the second column.  Then create your script to to a find and replace 

0 Kudos