我想检查字符串是否为空并及时解析字符串。
请找到下面的代码
valueStr = strings.Replace(string(valueStr), " ", "", -1)
valueStr = strings.Replace(string(valueStr), "\t", "", -1)
valueStr = strings.Replace(string(valueStr), "\n", "", -1)
valueStr = strings.Replace(string(valueStr), "\r", "", -1)
var re = regexp.MustCompile(`\s`)
valueStr = re.ReplaceAllString(valueStr, "")
if valueStr != "" {
fmt.Printf("-------- valueStr %c: \n", valueStr) // o/p => -------- valueStr %!c(string= ):
fmt.Printf("-------- valueStr %#v: \n", valueStr) // o/p => -------- valueStr "\x00":
fmt.Printf("-------- valueStr %x: \n", valueStr) // o/p => -------- valueStr 00:
fmt.Println("-------- valueStr length: ", len(valueStr)) // o/p => -------- valueStr length: 1
// considering valueStr is not empty, parse string to time
time, err := time.Parse(TIME_FORMAT, strings.TrimSpace(valueStr))
if err != nil {
fmt.Println("-------- Error converting time: ", err) // o/p => -------- Error converting time: parsing time " " as "15:04:05": cannot parse " " as "15"
return
}
} else {
// another code
}
如何从字符串中删除这个空字符?或者检查字符串是否包含这个空字符?
哆啦的时光机
泛舟湖上清波郎朗
BIG阳
相关分类