2023-05-13 00:55:47 +08:00
|
|
|
package str
|
2023-02-03 16:18:31 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStrUse(t *testing.T) {
|
|
|
|
const NoModify = "Don't edit this string. "
|
|
|
|
str := fmt.Sprintf(NoModify+"%s", "Do something")
|
|
|
|
|
|
|
|
bs := S2B(str)
|
|
|
|
bs[0] = 'L'
|
|
|
|
t.Log(str)
|
|
|
|
|
|
|
|
// 不可以对字面量量声明的字符串进行这种修改
|
|
|
|
t.Run("painc", func(t *testing.T) {
|
|
|
|
bs = S2B(NoModify)
|
|
|
|
bs[0] = 'L'
|
|
|
|
t.Log(NoModify)
|
|
|
|
})
|
|
|
|
}
|