增加字符串编码转换

This commit is contained in:
2022-07-09 14:42:31 +08:00
parent ec9271c0f3
commit 2936ec4ba5
3 changed files with 33 additions and 3 deletions

View File

@@ -13,6 +13,8 @@ import (
"math/rand"
"strings"
"time"
"github.com/axgle/mahonia"
)
// stringOperate ...
@@ -88,3 +90,16 @@ func (s *stringOperate) SnakeCaseToCamel(str string) string {
}
return builder.String()
}
// Convert 字符串编码转换
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:38 2022/7/9
func (s *stringOperate) Convert(str string, sourceCode string, targetCode string) string {
sourceCoder := mahonia.NewDecoder(sourceCode)
sourceResult := sourceCoder.ConvertString(str)
targetCoder := mahonia.NewDecoder(targetCode)
_, cdata, _ := targetCoder.Translate([]byte(sourceResult), true)
return string(cdata)
}