mirror of
https://github.com/wonli/aqi.git
synced 2024-06-28 09:57:05 +08:00
15 lines
326 B
Go
15 lines
326 B
Go
package utils
|
|
|
|
func LimitString(str string, limit int) string {
|
|
// Convert the string to a rune slice to properly handle Unicode characters
|
|
runes := []rune(str)
|
|
|
|
if len(runes) > limit {
|
|
// If the length exceeds the limit
|
|
// truncate the slice to the specified length
|
|
runes = runes[:limit]
|
|
}
|
|
|
|
return string(runes)
|
|
}
|