
Trim이라고 하는 그것입니다.
문자열에서 앞 또는 뒷쪽의 특정 문자열을 제거하는 코드입니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
// Go program to illustrate // how to trim a string package main import ( "fmt" "strings" ) // Main method func main() { // Creating and initializing string // Using shorthand declaration str1 := "!!Welcome to GeeksforGeeks !!" str2 := "@@This is the tutorial of Golang$$" // Displaying strings fmt.Println("Strings before trimming:") fmt.Println("String 1: ", str1) fmt.Println("String 2:", str2) // Trimming the given strings // Using Trim() function res1 := strings.Trim(str1, "!") res2 := strings.Trim(str2, "@$") // Displaying the results fmt.Println("\nStrings after trimming:") fmt.Println("Result 1: ", res1) fmt.Println("Result 2:", res2) } |