diff --git a/docs/convertor.md b/docs/convertor.md index d2e4d11..d1544cd 100644 --- a/docs/convertor.md +++ b/docs/convertor.md @@ -394,6 +394,32 @@ func main() { ``` +### ToString + +

ToString convert value to string, for number, string, []byte, will convert to string. For other type (slice, map, array, struct) will call json.Marshal

+ +Signature: + +```go +func ToString(value any) string +``` +Example: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/convertor" +) + +func main() { + fmt.Printf("%q", convertor.ToString(1)) //"1" + fmt.Printf("%q", convertor.ToString(1.1)) //"1.1" + fmt.Printf("%q", convertor.ToString([]int{1, 2, 3})) //"[1,2,3]" +} +``` + ### StructToMap diff --git a/docs/convertor_zh-CN.md b/docs/convertor_zh-CN.md index 1156292..8c185ef 100644 --- a/docs/convertor_zh-CN.md +++ b/docs/convertor_zh-CN.md @@ -400,7 +400,7 @@ func main() { ### ToString -

将interface转成字符串

+

将值转换为字符串,对于数字、字符串、[]byte,将转换为字符串。 对于其他类型(切片、映射、数组、结构)将调用 json.Marshal

函数签名: diff --git a/docs/slice.md b/docs/slice.md index ad81702..17a37b0 100644 --- a/docs/slice.md +++ b/docs/slice.md @@ -185,7 +185,7 @@ func main() { Signature: ```go -func Compact[T any](slice []T) []T +func Compact[T comparable](slice []T) []T ``` Example: diff --git a/docs/slice_zh-CN.md b/docs/slice_zh-CN.md index 7865b40..14a25c6 100644 --- a/docs/slice_zh-CN.md +++ b/docs/slice_zh-CN.md @@ -188,7 +188,7 @@ func main() { 函数签名: ```go -func Compact[T any](slice []T) []T +func Compact[T comparable](slice []T) []T ``` 例子: