Arcade & Python: Using "illegal" characters like "\" in Replace

525
5
Jump to solution
03-04-2021 06:46 AM
BrendonJoyce1
New Contributor III

Good morning all,

I have some URL fields with different facing "\" "/" slashes that need to be lined up to "/". When using arcade in a web map to try and Replace "\" , "/", the \ is invalid and cannot be replaced. This makes it so the expression can't complete itself with red ' and black end ).

Capture.JPG

Basically I have URL text like BS\09802098.pdf that needs to end up BS/09802098.pdf. I also tried this on ArcPro end with python and received similar issues.

Any ideas?

Thanks

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Honored Contributor

!CARDURL!.replace("\\", "/")   # python

if CARDURL is a field name


... sort of retired...

View solution in original post

5 Replies
DanPatterson
MVP Honored Contributor

!CARDURL!.replace("\\", "/")   # python

if CARDURL is a field name


... sort of retired...

View solution in original post

DavidPike
MVP Frequent Contributor

I think you need to specify '\\' so the backslash is properly returned

 

Replace($feature.CARDURL, '\\', '/')

 

MPach
by
New Contributor III

I don't know for sure, but I bet you have to use an escape character or rather I bet the  \  is being interpreted as an escape character. Have you tried '\\' yet? I think that should escape the backslash if I recall. 

https://www.freecodecamp.org/news/escape-sequences-python/

https://linuxconfig.org/list-of-python-escape-sequence-characters-with-examples

 

0 Kudos
DanPatterson
MVP Honored Contributor

look at my python example... the first \ is escaping the second \, so \\ means replace \ with /


... sort of retired...
BrendonJoyce1
New Contributor III

Thanks all, \\ works in replace!

0 Kudos