Notes Golang String

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
1 Package Main2 3 Import (4     "FMT"5     "StrConv"6     "Strings"7 )8 9 Func Main () {Ten//Strings Demo One Contains () A Join () - Index () - Repeat () the Replace () - Split () -  -//StrConv Demo + Appenddemo () - Formatdemo () + Parsedemo () A } at  - func Contains () { -Fmt. PRINTLN (Strings. Contains ("Seafood","Foo")) //true -Fmt. PRINTLN (Strings. Contains ("Seafood","Bar")) //false - } -  in func Join () { -s: = []string{"Foo","Bar","Baz"} toFmt. PRINTLN (Strings. Join (S,",")) //Foo,bar,baz + } -  the func Index () { *Fmt. PRINTLN (Strings. Index ("Chicken","Ken"))//4 $Fmt. PRINTLN (Strings. Index ("Chicken","DMR"))//-1Panax Notoginseng } -  the func Repeat () { +Fmt. Println ("BA"+ Strings. Repeat ("na", 2))//Banana A } the  + func Replace () { -Fmt. PRINTLN (Strings. Replace ("Oink Oink Oink","k","KY", 2))//oinky oinky Oink $Fmt. PRINTLN (Strings. Replace ("Oink Oink Oink","Oink","Moo",-1))//Moo Moo Moo $ } -  - func Split () { theFmt. Printf ("%q\n", strings. Split ("A,b,c",","))                        //["a" "b" "C"] -Fmt. Printf ("%q\n", strings. Split ("A man a plan a canal Panama","a")) //["" "Mans" "Plan" "Canal Panama"]WuyiFmt. Printf ("%q\n", strings. Split ("XYZ",""))                         //[" " "x" "y" "Z" " "] theFmt. Printf ("%q\n", strings. Split ("","Bernardo O ' Higgins"))            //[""] - } Wu  - func Appenddemo () { Aboutstr: = make ([]byte, 0, 100) $str = StrConv. Appendint (str, 4567, 10) -str =StrConv. Appendbool (str, FALSE) -str = StrConv. Appendquote (str,"ABCDEFG") -str = StrConv. Appendquoterune (str,'single') AFmt. PRINTLN (String (str))//4567false"ABCDEFG"'single' + } the  - func Formatdemo () { $A: =StrConv. Formatbool (False) theB: = StrConv. Formatfloat (123.23,'g', 12, 64) thec: = StrConv. Formatint (1234, 10) theD: = StrConv. Formatuint (12345, 10) theE: = StrConv. Itoa (1023) -Fmt. Println (A, B, C, D, E)//False 123.23 1234 12345 1023 in } the  the func Parsedemo () { AboutA, err: = StrConv. Parsebool ("false") the Handleerr (Err) theB, err: = StrConv. Parsefloat ("123,23", 64) the Handleerr (Err) +C, err: = StrConv. parseint ("1234", 10, 64) - Handleerr (Err) theD, err: = StrConv. Parseuint ("12345", 10, 64)Bayi Handleerr (Err) theE: = StrConv. Itoa (1023) the Handleerr (Err) -Fmt. Println (A, B, C, D, E)//False 0 1234 12345 1023 - } the  the func Handleerr (err error) { the     ifErr! =Nil { the FMT. PRINTLN (ERR) -     } the}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.