Golang strconv.UnquoteChar() function example

package strconv

Golang strconv.UnquoteChar() function usage example

 package main

 import (
  "fmt"
  "strconv"
 )

 func main() {
  // func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, err error)

  text := "'t' - is an example rune"

  rune, needmultibyte, tail, err := strconv.UnquoteChar(text[1:], text[0]) // quote byte text[0] = '

  if err != nil {
 fmt.Println(err)
  }

  fmt.Println("A unquoted char looks like :", rune)
  fmt.Println("A unquoted char looks like :", string(rune))

  fmt.Println("Need multibyte? :", needmultibyte)

  fmt.Println("Tail : ", tail)

 }

Reference :

http://golang.org/pkg/strconv/#UnquoteChar

Advertisement