点击运行
package main import ( "fmt" "strings" ) // Main 函数 func main() { // 创建并初始化字符串 str1 := "Welcome to jiyik.com" str2 := "This is the tutorial of Golang" // 显示字符串 fmt.Println("Strings before trimming:") fmt.Println("String 1: ", str1) fmt.Println("String 2:", str2) // 使用 TrimRight() 函数 res1 := strings.TrimSuffix(str1, "jiyik.com") res2 := strings.TrimSuffix(str2, "Hello") // 显示结果 fmt.Println("\nStrings after trimming:") fmt.Println("Result 1: ", res1) fmt.Println("Result 2:", res2) }
运行结果 :
正在执行...