I have the follow URL and I want to change the value of start
for each iteration. Is there a better way to do it?
test := "https://www.googleapis.com/customsearch/v1?start=%d&cx=001106611627702700888%3Aaonktv-oz_w&q=bells%20palsy%20mouth&exactTerms=palsy&fileType=png&imgColorType=color&imgType=face&searchType=image&key=AIzaSyAYqQ4IxUHnF7rfvzSvnczxQ-u93AbkC8k"
for v := 1; v < 100; v += 10 {
val := fmt.Sprintf(test, v)
fmt.Println(val)
}
Output now: https://www.googleapis.com/customsearch/v1?start=1&cx=001106611627702700888%!A(MISSING)aonktv-oz_w&q=bells%!p(MISSING)alsy%!m(MISSING)outh&exactTerms=palsy&fileType=png&imgColorType=color&imgType=face&searchType=image&key=AIzaSyAYqQ4IxUHnF7rfvzSvnczxQ-u93AbkC8k
Expected Output should be: https://www.googleapis.com/customsearch/v1?startindex=1&q=bells%20palsy%20mouth https://www.googleapis.com/customsearch/v1?startindex=11&q=bells%20palsy%20mouth
....etc.
Why Sprintf
gives me (MISSING)
and a couple of random characters?
The %
characters that are not part of a format verb should be escaped as %%
:
test := "https://www.googleapis.com/customsearch/v1?start=%d&cx=001106611627702700888%%3Aaonktv-oz_w&q=bells%%20palsy%%20mouth&exactTerms=palsy&fileType=png&imgColorType=color&imgType=face&searchType=image&key=AIzaSyAYqQ4IxUHnF7rfvzSvnczxQ-u93AbkC8k"
If the %
are not escaped, then fmt expects to find a corresponding argument and complains with the output (MISSING)
when the argument is not found.