Select to view content in your preferred language

Using Field Calculator to Add/Complete a Hyperlink

1749
2
Jump to solution
05-25-2022 01:57 PM
Labels (2)
DerekWood
Emerging Contributor

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?

0 Kudos
1 Solution

Accepted Solutions
Brian_Wilson
Honored Contributor

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"\\")

 

View solution in original post

2 Replies
Brian_Wilson
Honored Contributor

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"\\")

 

DerekWood
Emerging Contributor

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")

0 Kudos