Open In App

strconv package in Golang

Last Updated : 28 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Function Description
func AppendBool This function is used to appends true or false according to the value of x, to dst and returns the extended buffer.
func AppendFloat This 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 AppendInt This function is used to appends the string form of the integer i, as generated by FormatInt, to dst and returns the extended buffer.
func AppendQuote This 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 AppendQuoteRune This 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 AppendQuoteRuneToASCII This 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 AppendQuoteRuneToGraphic This 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 AppendQuoteToASCII This 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 AppendQuoteToGraphic This 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 AppendUint This 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 Atoi This function is equivalent to ParseInt(s, 10, 0) and converted to type int.
func CanBackquote This 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 FormatBool This function is used to return true or false according to the value of x.
func FormatFloat This function is used to converts the floating-point number f to a string, according to the format fmt and precision prec.
func FormatInt This function is used to return the string representation of i in the given base, for 2 <= base <= 36.
func FormatUint This function is used to return the string representation of i in the given base, for 2 <= base <= 36.
func IsGraphic This function is used to check whether the rune is defined as a Graphic by Unicode.
func IsPrint This 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 Itoa This function is equivalent to FormatInt(int64(i), 10).
func ParseBool This function is used to returns the boolean value represented by the string.
func ParseFloat This 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 ParseInt This 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 ParseUint This function is like ParseInt but for unsigned numbers.
func Quote This function is used to returns a double-quoted Go string literal representing s.
func QuoteRune This function is used to returns a single-quoted Go character literal representing the rune.
func QuoteRuneToASCII This function is used to returns a single-quoted Go character literal representing the rune.
func QuoteRuneToGraphic This function is used to returns a single-quoted Go character literal representing the rune.
func QuoteToASCII This function is used to returns a double-quoted Go string literal representing s.
func QuoteToGraphic This function is used to returns a double-quoted Go string literal representing s.
func Unquote This function interpret s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes.
func UnquoteChar This 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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads