func main() { newlist := strconv.AppendQuoteRune(make([]byte, 0), 'a') fmt.Println(string(newlist)) newlist = strconv.AppendQuoteRune(make([]byte, 0), '\'') fmt.Println(string(newlist)) newlist = strconv.AppendQuoteRune(make([]byte, 0), '中') fmt.Println(string(newlist)) }
func ExampleAppendQuoteRune() { b := []byte("rune:") b = strconv.AppendQuoteRune(b, '☺') fmt.Println(string(b)) // Output: // rune:'☺' }
// fmt_qc formats the integer as a single-quoted, escaped Go character constant. // If the character is not valid Unicode, it will print '\ufffd'. func (f *fmt) fmt_qc(c int64) { var quoted []byte if f.plus { quoted = strconv.AppendQuoteRuneToASCII(f.intbuf[0:0], rune(c)) } else { quoted = strconv.AppendQuoteRune(f.intbuf[0:0], rune(c)) } f.pad(quoted) }
func AppendTest() { //Append 系列函数将整数等转换为字符串后,添加到现有的字节数组中。 str := make([]byte, 0, 100) str = strconv.AppendInt(str, 4567, 10) str = strconv.AppendBool(str, false) str = strconv.AppendQuote(str, "abcdefg") str = strconv.AppendQuoteRune(str, '单') fmt.Println(string(str)) }
// fmt_qc formats an integer as a single-quoted, escaped Go character constant. // If the character is not valid Unicode, it will print '\ufffd'. func (f *fmt) fmt_qc(c uint64) { r := rune(c) if c > utf8.MaxRune { r = utf8.RuneError } buf := f.intbuf[:0] if f.plus { f.pad(strconv.AppendQuoteRuneToASCII(buf, r)) } else { f.pad(strconv.AppendQuoteRune(buf, r)) } }
func Teststrings() { //字符串s中是否包含substr,返回bool值 fmt.Println(strings.Contains("seafood", "foo")) fmt.Println(strings.Contains("seafood", "bar")) fmt.Println(strings.Contains("seafood", "")) fmt.Println(strings.Contains("", "")) s := []string{"foo", "bar", "baz"} //字符串链接,把slice a通过sep链接起来 fmt.Println(strings.Join(s, ", ")) //在字符串s中查找sep所在的位置,返回位置值,找不到返回-1 fmt.Println(strings.Index("chicken", "ken")) fmt.Println(strings.Index("chicken", "dmr")) //重复s字符串count次,最后返回重复的字符串 fmt.Println("ba" + strings.Repeat("na", 2)) //在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换 fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2)) fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1)) //把s字符串按照sep分割,返回slice fmt.Printf("%q\n", strings.Split("a,b,c", ",")) fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a ")) fmt.Printf("%q\n", strings.Split(" xyz ", "")) fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins")) //在s字符串中去除cutset指定的字符串 fmt.Printf("[%q]\n", strings.Trim(" !!! Achtung !!! ", "! ")) //去除s字符串的空格符,并且按照空格分割返回slice fmt.Printf("Fields are: %q\n", strings.Fields(" foo bar baz ")) //Append 系列函数将整数等转换为字符串后,添加到现有的字节数组中。 str := make([]byte, 0, 100) str = strconv.AppendInt(str, 4567, 10) str = strconv.AppendBool(str, false) str = strconv.AppendQuote(str, "abcdefg") str = strconv.AppendQuoteRune(str, '单') fmt.Println(string(str)) //Format 系列函数把其他类型的转换为字符串 a := strconv.FormatBool(false) b := strconv.FormatFloat(123.23, 'g', 12, 64) c := strconv.FormatInt(1234, 10) d := strconv.FormatUint(12345, 10) e := strconv.Itoa(1023) fmt.Println(a, b, c, d, e) }
func main() { str := make([]byte, 0, 100) str = strconv.AppendInt(str, 4567, 10) str = strconv.AppendBool(str, false) str = strconv.AppendQuote(str, "adcdef") str = strconv.AppendQuoteRune(str, '中') fmt.Println(string(str)) fl := strconv.FormatFloat(123.23, 'g', 12, 64) fmt.Println(fl) ui, err := strconv.ParseUint("12345", 10, 64) if err != nil { fmt.Println(err) } fmt.Println(ui + 10) }
func processString() { str := make([]byte, 0, 100) // str := "" fmt.Println(str) str = strconv.AppendInt(str, 4567, 10) str = strconv.AppendBool(str, false) str = strconv.AppendQuote(str, "abcde") str = strconv.AppendQuoteRune(str, '周') fmt.Println(str) fmt.Println(string(str)) str1 := strconv.FormatBool(false) fmt.Println(str1) str1 = strings.Repeat(str1, 2) fmt.Println(str1) fmt.Println(strings.Contains(str1, "al")) fmt.Println(strings.Index(str1, "al")) fmt.Println(strings.Trim("!a james May !a", "!a")) }
func main() { // Append , 转换并添加到现有字符串 str := make([]byte, 0, 1000) str = strconv.AppendInt(str, 4567, 10) str = strconv.AppendBool(str, false) str = strconv.AppendQuote(str, "abcdefg") str = strconv.AppendQuoteRune(str, '单') fmt.Println(string(str)) // Format 把其他类型转成字符串 a := strconv.FormatBool(false) b := strconv.FormatFloat(123.23, 'g', 12, 64) c := strconv.FormatInt(1234, 10) d := strconv.FormatUint(12345, 10) e := strconv.Itoa(1023) fmt.Println(a, b, c, d, e) // Parse 把字符串转为其他类型 a1, err := strconv.ParseBool("false") if err != nil { fmt.Println(err) } else { fmt.Println(a1) } b1, err := strconv.ParseFloat("123.23", 64) c1, err := strconv.ParseInt("1234", 10, 64) d1, err := strconv.ParseUint("12345", 10, 64) fmt.Println(a1, b1, c1, d1) }
func Backspace(g *gocui.Gui, v *gocui.View) error { cx, cy := v.Cursor() spaceCount := 0 var s []byte for i := 0; i < 5; i++ { rune, err := g.Rune(cx+(6-i), cy) if err == nil { res := strconv.AppendQuoteRune(s, rune) if string(res) == "' '" { spaceCount++ } } if spaceCount == 4 { for c := 1; c < 4; c++ { v.DeleteRune(cx-c, cy) v.SetCursor(cx-c, cy) } } } return nil }
func (bs Bytes) AppendQuoteRune(r rune) Bytes { t := strconv.AppendQuoteRune([]byte(bs), r) return Bytes(t) }