How to create string with double quotes in Go

4 Answers

0 votes
package main 
    
import ( 
    "fmt"
) 
 
func main() { 
    str := "go java c c++ python"
    
    quoted := fmt.Sprintf("%q", str)
    fmt.Println(quoted)
} 
    
     
     
   
      
/*
run:
       
"go java c c++ python"
   
*/

 



answered Jun 10, 2023 by avibootz
0 votes
package main 
    
import ( 
    "fmt"
) 
 
func main() { 
    str := "go java c c++ python"
    
    quoted := fmt.Sprintf("\"%s\"", str)
    fmt.Println(quoted)
} 
    
     
     
   
      
/*
run:
       
"go java c c++ python"
   
*/

 



answered Jun 10, 2023 by avibootz
0 votes
package main 
    
import ( 
    "fmt"
) 
 
func main() { 
    str := `"go java c c++ python"`
    
    fmt.Printf("%s", str)
} 
    
     
     
   
      
/*
run:
       
"go java c c++ python"
   
*/

 



answered Jun 10, 2023 by avibootz
0 votes
package main 
    
import ( 
    "fmt"
    "strconv"
) 
 
func main() { 
    str := `"go java c c++ python"`
    
    fmt.Println(strconv.Quote(str))
} 
    
     
     
   
      
/*
run:
       
"\"go java c c++ python\""
   
*/

 



answered Jun 10, 2023 by avibootz

Related questions

3 answers 235 views
235 views asked Jun 10, 2023 by avibootz
1 answer 145 views
1 answer 164 views
1 answer 185 views
185 views asked Aug 19, 2020 by avibootz
...