临时要用到 go 的字符串截取功能,别人发来的c++代码一大坨,go我也用得不熟,试试chatgpt,还是比google来的好用。
package main
import (
"fmt"
"strings"
)
func main() {
str := "This is <some> text with <multiple> pairs of <angle brackets>"
startIndex := strings.Index(str, "<")
endIndex := strings.LastIndex(str, ">")
if startIndex == -1 || endIndex == -1 {
fmt.Println("No angle brackets found")
return
}
content := str[startIndex+1 : endIndex]
fmt.Println(content)
}
package main
import (
"fmt"
"time"
)
func main() {
t, err := time.Parse(time.RFC3339, "2023-03-07T06:04:23Z")
if err != nil {
fmt.Println("Error parsing time:", err)
return
}
fmt.Println(t.Unix())
}