ai_scheduler/internal/pkg/util/string.go

35 lines
710 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package util
import (
"encoding/json"
"strconv"
"strings"
)
// 占位符替换 xxx{placeholder}xxx
func ReplacePlaceholder(str string, placeholder string, value string) string {
return strings.ReplaceAll(str, "{"+placeholder+"}", value)
}
// 构建跳转a标签新tab打开
func BuildJumpLink(url string, text string) string {
return "<a href=\"" + url + "\" target=\"_blank\">" + text + "</a>"
}
func EscapeJSONString(s string) string {
b, _ := json.Marshal(s)
return string(b[1 : len(b)-1])
}
// string 转 int
func StringToInt(s string) int {
i, _ := strconv.Atoi(s)
return i
}
// string 转 float64
func StringToFloat64(s string) float64 {
i, _ := strconv.ParseFloat(s, 64)
return i
}