GO language commonly used standard library 01 --- strings package

main Package 

Import ( 
	"FMT" 
	"strings" 
) 

FUNC main031 () { 
	fmt.Printf ( "in characters:% C; \ n-", 0x007B) {// 
	fmt.Printf ( "the UTF8 code value (ID) in the form:% U; \ n "," sister ") // the U-007B + 
} 

/ * search character string * / 
FUNC main () { 
	// determines whether a string contains the substring s substr. 
	fmt.Println (strings.Contains ( "your sister ah," "I")) // false 
	fmt.Println (strings.Contains ( "your sister ah," "your sister")) to true // 

	// string judgment s contain utf-8 code value r. 
	fmt.Println (strings.ContainsRune ( "your sister ah {", 0x59b9)) // true contain the characters "sister" 
	fmt.Println (strings.ContainsRune ( "{your sister ah ',' sister ')) // to true 
	fmt .Println (strings.ContainsRune ( "{your sister ah ',' wave '


	// sep position of the substring in the string s first occurrence 
	fmt.Println (strings.Index ( "Hello", "H")) // 0 
	fmt.Println (strings.Index ( "Hello", "E ")) // 1 
	fmt.Println (strings.Index (" the Hello "," hex ")) // - 1 substring does not exist 
	fmt.Println (strings.Index (" your sister ah, "" sister ")) // 3 UTF8 character set, a character occupy 3 bytes, a "position" as used herein, a byte position corresponding to a 

	// string chars either a utf-8 code value for the first time in s position, or if there is an empty string is returned chars -1. 
	fmt.Println (strings.IndexAny ( "the Hello", "asshole")) // 0 
	fmt.Println (strings.IndexAny ( "glad your sister ah," "laugh your head")) // 6 (UTF8 character set a 3 bytes representing characters) 
}

  

Guess you like

Origin www.cnblogs.com/yunweiqiang/p/11831059.html