golang strings commonly used functions

 1 package main
 2 
 3 import (
 4     "fmt"
 5     "strings"
 6 )
 7 
 8 func main() {
 9 
10     s1 := " aBc"
11     s2 := "100a"
12     s3 := s1 + s2
13     fmt.Println(s3)
14     fmt.Println(strings.HasPrefix(s3, "a")) //判断前缀
15     fmt.Println(strings.HasSuffix(s3, "0")) // Analyzing suffix 
16      fmt.Println (strings.Contains (S3, " . 9 " ))   // string contains the relationship 
. 17      fmt.Println (strings.Index (S3, " 0 " ))      // Analyzing substring or the position (index) in the parent character string appearing 
18 is      fmt.Println (strings.LastIndex (S3, " 0 " )) // index position of the last occurrence 
. 19      fmt.Println (strings.Replace (S3, " 0 " , " 1 " - 1 )) // if n = -1 then replaces all 
20     fmt.Println (strings.Count (S3, " 0 " )) // non-overlapping occurrences of 
21 is      fmt.Println (strings.Repeat (S3, 2 )) // repeat string 
22 is      fmt.Println (strings.ToLower ( S3)) // modify the case of the string 
23 is      fmt.Println (strings.ToUpper (S3)) // modify the case of the string 
24      fmt.Println (strings.TrimSpace (S3)) // trim beginning and end of the string removed spaces 
25      fmt.Println (strings.Trim (strings.TrimSpace (S3), " A " )) // trimmer string beginning and end of the string removed 
26 }

 

Guess you like

Origin www.cnblogs.com/lvcisco/p/11777071.html