golang based learning -strings package of commonly used functions to learn

main Package 

Import ( 
	"FMT" 
	"strings" 
) 

// String Description StrFunc 
FUNC main () { 
	var TestStr String 
	TestStr = "seetatech" 
	testStrTrim: = "Seeta Tech" 
	checkStr: = "Tech" 
	fmt.Println ( "- ----: "+ TestStr +": ----- ") 
	// verify comprising 
	fmt.Println (strings.Contains (TestStr, checkStr)) 
	// calculate the number of characters in a string comprising 
	fmt.Println (strings .count (TestStr, checkStr)) 
	// string length is calculated 
	fmt.Println (len (TestStr)) 
	// string into 
	splitStr: = strings.Split (TestStr, "T") 
	fmt.Println (splitStr) 
	// character string concatenation 
	fmt.Println (strings.Join (splitStr, "t ")) 
	// String replace

	fmt.Println (strings.Replace (TestStr, "Seeta", "firevison", 1)) 
	// all lowercase 
	fmt.Println (strings.ToLower (TestStr)) 
	// all uppercase 
	fmt.Println (strings.ToUpper (testStr) ) 
	// to be filtered to remove about character 
	fmt.Println (strings.Trim (testStrTrim, "")) 
	// remove the left to filter character 
	fmt.Println (strings.TrimLeft (testStrTrim, "")) 
	// remove the right to be filtered character 
	fmt.Println (strings.TrimRight (testStrTrim, "")) 
	// position of the characters that appear 
	fmt.Println (strings.Index ( "go gopher" , "go")) 
	location // last occurrence of 
	fmt. println (strings.LastIndex ( "Go Gopher", "Go")) 
	// no positioned character display -1 
	fmt.Println (strings.LastIndex ( "Go Gopher", "Rodent")) 

}

  

Guess you like

Origin www.cnblogs.com/saryli/p/11373388.html