<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ### 判斷前綴、后綴 ``` // HasPrefix 判斷字符串 str 是否以 prefix 開頭: strings.HasPrefix(str, prefix string) bool package main import ( "fmt" "strings" ) func main() { str := "hello world" res := strings.HasPrefix(str, "he") fmt.Println(res) // true } ``` ``` // HasSuffix 判斷字符串 str 是否以 suffix 結尾: strings.HasSuffix(str, suffix string) bool func main() { str := "hello world" res := strings.HasSuffix(str, "wo") fmt.Println(res) // false } ``` ### 判斷是否包含字符串 ``` // Contains 判斷字符串 str 是否包含 substr: strings.Contains(str, substr string) bool func main() { str := "hello world" res := strings.Contains(str, " ") fmt.Println(res) // true } ``` ### 判斷子字符串或字符在父字符串中出現的位置(索引) ``` // Index 返回字符串 s 在字符串 str 中的索引,-1 表示字符串 str 不包含字符串 s: strings.Index(str, s string) int func main() { str := "hello world" res := strings.Index(str, "o") fmt.Println(res) // 4 } ``` ``` // LastIndex 返回字符串 s 在字符串 str 中最后出現位置的索引,-1 表示字符串 str 不包含字符串 s: strings.LastIndex(s, str string) int func main() { str := "hello world" res := strings.LastIndex(str, "o") fmt.Println(res) // 7 } ``` ### 字符串替換 ``` Replace 用于將字符串 str 中的前 n 個字符串 old 替換為字符串 new,并返回一個新的字符串,如果 n = -1 則替換所有字符串 old 為字符串 new: strings.Replace(str, old, new, n) string func main() { str := "hello world" res := strings.Replace(str, " ", "-", 1) fmt.Println(res) // hello-world } ``` ### 統計字符串出現次數 ``` //Count 用于計算字符串 s 在字符串 str 中出現的非重疊次數: strings.Count(str, s string) int func main() { str := "hello world" res := strings.Count(str, "o") fmt.Println(res) // 2 } ``` ### 重復字符串 ``` // Repeat 用于重復 count 次字符串 str 并返回一個新的字符串: strings.Repeat(s, count int) string func main() { str := "hello world" res := strings.Repeat(str, 2) fmt.Println(res) // hello worldhello world } ``` ### 修改字符串大小寫 ``` // ToLower 將字符串中的 Unicode 字符全部轉換為相應的小寫字符: strings.ToLower(str) string func main() { str := "Hello WORLD" res := strings.ToLower(str) fmt.Println(res) // hello world } // ToUpper 將字符串中的 Unicode 字符全部轉換為相應的大寫字符: strings.ToUpper(str) string func main() { str := "Hello world" res := strings.ToUpper(str) fmt.Println(res) // HELLO WORLD } ``` ### 修剪字符串 ``` // 你可以使用 strings.TrimSpace(str) 來剔除字符串開頭和結尾的空白符號;如果你想要剔除指定字符,則可以使用 strings.Trim(str, "cut") 來將開頭和結尾的 cut 去除掉。該函數的第二個參數可以包含任何字符,如果你只想剔除開頭或者結尾的字符串,則可以使用 TrimLeft 或者 TrimRight 來實現。區分大小寫 func main() { str := "Hello world" res := strings.Trim(str, "He") fmt.Println(res) // llo world } ``` ### 分割字符串 ``` // strings.Fields(str) 利用空白作為分隔符將字符串分割為若干塊,并返回一個 slice 。如果字符串只包含空白符號,返回一個長度為 0 的 slice 。 // strings.Split(str, sep) 自定義分割符號 sep 對字符串分割,返回 slice 。 ``` ### 拼接 slice 到字符串 ``` // Join 用于將元素類型為 string 的 slice 使用分割符號來拼接組成一個字符串: strings.Join(sl []string, sep string) string func main() { str := "H-e-l-l-o world" s2 := strings.Split(str, "-") res := strings.Join(s2, "|") fmt.Printf("%q", res) // "H|e|l|l|o world" } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看