Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,950 questions

51,892 answers

573 users

How to split URL and get the parameters from URL in Go

1 Answer

0 votes
package main
  
import (
    "encoding/hex"
    "fmt"
    "strings"
)
  
func main() {
    url := `http://www.seek4info.com/search/result/?q=web%20hosting&view=0`
    pq := strings.Split(url, "?")[1]
	fmt.Printf("pq: %s\n", pq)
    params := strings.Split(pq, "&")
  	fmt.Printf("params: %s\n", params)
	
    for _, param := range params {
        percent := strings.Split(param, "%")
        fmt.Printf("percent: %s\n", percent)
        var s string
        if len(percent) > 1 {
            for i, part := range percent {
                fmt.Printf("part: %s\n", part)
                if i == 0 {
                    s += part
                } else {
                    bl, _ := hex.DecodeString(part[:2])
                    tmp := string(bl)
                    s += tmp
                    s += part[2:]
                }
                 
            }
        } else {
            s = param
        }
        fmt.Printf("(result)s: %s\n", s)
    }
}
 
 
 
/*
run:
 
pq: q=web%20hosting&view=0
params: [q=web%20hosting view=0]
percent: [q=web 20hosting]
part: q=web
part: 20hosting
(result)s: q=web hosting
percent: [view=0]
(result)s: view=0
 
*/

 



answered Aug 14, 2020 by avibootz
edited Aug 14, 2020 by avibootz

Related questions

1 answer 154 views
154 views asked Aug 7, 2020 by avibootz
1 answer 154 views
2 answers 91 views
1 answer 156 views
1 answer 207 views
1 answer 145 views
1 answer 135 views
135 views asked Aug 15, 2020 by avibootz
...