Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

strconv package in Golang

  • Last Updated : 28 Jul, 2020

Go language provides a strconv package that implements conversions to and from string representations of basic data types. To access the functions of the strconv package you need to import the strconv package in your program with the help of the import keyword.

FunctionDescription
func AppendBoolThis function is used to appends true or false according to the value of x, to dst and returns the extended buffer.
func AppendFloatThis function is used to appends the string form of the floating-point number f, as generated by FormatFloat, to dst and returns the extended buffer.
func AppendIntThis function is used to appends the string form of the integer i, as generated by FormatInt, to dst and returns the extended buffer.
func AppendQuoteThis function is used to appends a double-quoted Go string literal representing s, as generated by Quote, to dst and returns the extended buffer.
func AppendQuoteRuneThis function is used to appends a single-quoted Go character literal representing the rune, as generated by QuoteRune, to dst and returns the extended buffer.
func AppendQuoteRuneToASCIIThis function is used to appends a single-quoted Go character literal representing the rune, as generated by QuoteRuneToASCII, to dst and returns the extended buffer.
func AppendQuoteRuneToGraphicThis function is used to appends a single-quoted Go character literal representing the rune, as generated by QuoteRuneToGraphic, to dst and returns the extended buffer.
func AppendQuoteToASCIIThis function is used to appends a double-quoted Go string literal representing s, as generated by QuoteToASCII, to dst and returns the extended buffer.
func AppendQuoteToGraphicThis function is used to appends a double-quoted Go string literal representing s, as generated by QuoteToGraphic, to dst and returns the extended buffer.
func AppendUintThis function is used to appends the string form of the unsigned integer i, as generated by FormatUint, to dst and returns the extended buffer.
func AtoiThis function is equivalent to ParseInt(s, 10, 0) and converted to type int.
func CanBackquoteThis function is used to check whether the given string can be represented unchanged as a single-line backquoted string without control characters other than tab.
func FormatBoolThis function is used to return true or false according to the value of x.
func FormatFloatThis function is used to converts the floating-point number f to a string, according to the format fmt and precision prec.
func FormatIntThis function is used to return the string representation of i in the given base, for 2 <= base <= 36.
func FormatUintThis function is used to return the string representation of i in the given base, for 2 <= base <= 36.
func IsGraphicThis function is used to check whether the rune is defined as a Graphic by Unicode.
func IsPrintThis function is used to check whether the rune is defined as printable by Go, with the same definition as unicode.IsPrint: letters, numbers, punctuation, symbols and ASCII space.
func ItoaThis function is equivalent to FormatInt(int64(i), 10).
func ParseBoolThis function is used to returns the boolean value represented by the string.
func ParseFloatThis function is used to converts the string s to a floating-point number with the precision specified by bitSize: 32 for float32, or 64 for float64.
func ParseIntThis function interpret a string str in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.
func ParseUintThis function is like ParseInt but for unsigned numbers.
func QuoteThis function is used to returns a double-quoted Go string literal representing s.
func QuoteRuneThis function is used to returns a single-quoted Go character literal representing the rune.
func QuoteRuneToASCIIThis function is used to returns a single-quoted Go character literal representing the rune.
func QuoteRuneToGraphicThis function is used to returns a single-quoted Go character literal representing the rune.
func QuoteToASCIIThis function is used to returns a double-quoted Go string literal representing s.
func QuoteToGraphicThis function is used to returns a double-quoted Go string literal representing s.
func UnquoteThis function interpret s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes.
func UnquoteCharThis function decodes the first character or byte in the escaped string or character literal represented by the string s.

Example 1:




// Golang program to illustrate the 
// strconv.AppendQuoteRuneToASCII() function
package main
  
import (
    "fmt"
    "strconv"
)
  
func main() {
  
         // Converting Unicode characters to 
         // ASCII strings resulting from "single quotes"
         // append the result to the end of the given []byte
         // Using AppendQuoteRuneToASCII() function
         num := []byte("Rune : ")
         num = strconv.AppendQuoteRuneToASCII(num, 'c')
         fmt.Println(string(num))
  
}

Output:

Rune : 'c'

Example 2 :




// Golang program to illustrate 
// strconv.Atoi() function 
package main 
   
import
    "fmt"
    "strconv"
   
func main() { 
   
    // Using Atoi() function 
    a := "244"
    b, e := strconv.Atoi(a) 
    if e == nil { 
        fmt.Printf("%T \n %v", b, b) 
    
   

Output:

int 
 244



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!