I am trying to populate the hyperlinks for photos of assets that my work maintains. When trying to Field Calc all of the HyperLink cell values for the selected rows to the root folder of all the photos, '\\bccstm01\Technical Services\Stormwater Asset Photos\', it left out the first backward slash. When trying to field calc in the additional backslash using the Python 3 replace( , ) expression I am left with no changes made.
Is there a recommended/suggested workaround for this issue?
Solved! Go to Solution.
If they are hyperlinks (like a URL) you should use forward slashes.
If they are files instead forward slashes will always work but if you really want to use backslashes you either need to use the "r" thing with python like mystring=r"\\server\dir\file.png" or double them up like mystring="\\\\server\\dir\\file.png".
This is because "\" means "the next thing is special" for example "\t" is a TAB character or "\n" is a NEWLINE and "\\" is a BACKSLASH character.
Using replace you would do something like this
s = r"\thisisthestring"
s = s.replace(r"\", r"\\")
If they are hyperlinks (like a URL) you should use forward slashes.
If they are files instead forward slashes will always work but if you really want to use backslashes you either need to use the "r" thing with python like mystring=r"\\server\dir\file.png" or double them up like mystring="\\\\server\\dir\\file.png".
This is because "\" means "the next thing is special" for example "\t" is a TAB character or "\n" is a NEWLINE and "\\" is a BACKSLASH character.
Using replace you would do something like this
s = r"\thisisthestring"
s = s.replace(r"\", r"\\")
Thank you for explaining this so well! I have done some coding in other languages, but I am unfamiliar with Python so I was unaware of my programming error in there.
I ran the update successfully utilizing the expression: !HyperLink!.replace(r"\b",r"\\b")