1 개요[ | ]
- Go substrBefore()
- Go stringBefore()
Go
Copy
package main
import (
"fmt"
"strings"
)
func substrBefore(haystack string, needle string) string {
pos := strings.Index(haystack, needle)
if pos == -1 {
return ""
}
return haystack[:pos]
}
func main() {
fmt.Println(substrBefore("hello world", "l")) // he
fmt.Println(substrBefore("hello world", "ll")) // he
fmt.Println(substrBefore("hello world", "x")) //
}
Loading
2 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.