1、中文字符串宽度为1 ,如果要按字节宽度求值,需用函数
s1 = "中国"
Console.WriteLine(s1.Length)
Console.WriteLine(System.Text.Encoding.Default.GetByteCount(s1)) '获得汉字的宽度
2、字符串的replace操作将生成一个新的字符串,与原来的字符串不同
s1 = "123"
Console.WriteLine(s1)
Console.WriteLine(s1.GetHashCode())
Console.WriteLine(s1.Replace("1", "!!!!"))
Console.WriteLine(s1)
Console.WriteLine(s1.GetHashCode())
结果
123
193359061
!!!!23
123
193359061
博客介绍了中文字符串宽度求值方法,指出中文字符串宽度为1,按字节宽度求值需用函数。还讲解了字符串的replace操作,该操作会生成新字符串,与原字符串不同,并给出了相应代码示例及运行结果。
405

被折叠的 条评论
为什么被折叠?



