I have 600 records that I need to be linked on a website. As clickable urls. But when I have the URL's, they only link to the 1st set of text before a space. So is there a code in QGIS that I can put in to alleviate this. I have tried: replace( "url"," ") with "%20" But this requires some more work.
2 Answers
You're close, you just need to put %20
inside the expression surrounded by single quotes (used to denote string) instead of double quotes (used to denote field names).
So you could use:
replace("url", ' ', '%20')
Note that this replaces all spaces in each string so you may need to be mindful, especially in cases where you might have a space at the end of a string.
-
I need to finish a query to replace some text in the QGIS query. I have got this so far: replace("url", 'Y:\Natural Environment Record\', 'exmoor-nationalpark.gov.uk/PAttachments//NER/') It through s a error. I have a section of text that I need to replace. Commented Sep 13, 2017 at 13:35
-
@MattSully - What error does it throw? I'm guessing it's due to the slashes you used as it will read this if you don't escape them correctly.– JosephCommented Sep 13, 2017 at 13:40
-
Parser Error: syntax error, unexpected COLUMN_REF, expecting COMMA or ')' Eval Error: No root node! Parsing failed? Commented Sep 13, 2017 at 13:41
-
1try
'Y:\\Natural Environment Record\\'
with doubled backslashes– JimmyCommented Sep 13, 2017 at 16:19 -
There's more than just space that is not "URL safe".
If you are looking to URL encode your strings, try (for Python 2):
import urllib
url = urllib.urlencode(url)
This will handle spaces and a whole lot more.
This post has a quick table of the different characters you need to encode.