积极答复者
C#怎样在多种编码混排的字符串中区分单双字节的字?

问题
答案
-
获取字符的字节数
System.Text.Encoding.Default.GetByteCount("a")
参照:http://www.biye5u.com/article/Csharp/jichu/2011/4320.html
http://blog.csdn.net/zx13525079024- 已标记为答案 Cookie Luo 2011年6月2日 8:35
-
你好,在2楼的提示下,补充给一个完整的答案:
【输出】
我<===>2
是<===>2
I<===>1【程序】
public class Test
{
static List<KeyValuePair<string, int>> GetCharBytes(string s)
{
List<KeyValuePair<string,int>> bytes = new List<KeyValuePair<string,int>>();foreach (var item in s)
{
bytes.Add(new KeyValuePair<string,int>(item+"",Encoding.Default.GetByteCount(item+"")));
}return bytes;
}
//主函数
public static void Main(String[] args)
{
string s = "我是I";foreach (var item in GetCharBytes(s))
{
Console.WriteLine(item.Key+"<===>"+item.Value);
}
}}
如果你有其它意见或私下交流,请发送邮件到:maledong@qq.com;或者请QQ我
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 Cookie Luo 2011年6月2日 8:35
全部回复
-
获取字符的字节数
System.Text.Encoding.Default.GetByteCount("a")
参照:http://www.biye5u.com/article/Csharp/jichu/2011/4320.html
http://blog.csdn.net/zx13525079024- 已标记为答案 Cookie Luo 2011年6月2日 8:35
-
你好,在2楼的提示下,补充给一个完整的答案:
【输出】
我<===>2
是<===>2
I<===>1【程序】
public class Test
{
static List<KeyValuePair<string, int>> GetCharBytes(string s)
{
List<KeyValuePair<string,int>> bytes = new List<KeyValuePair<string,int>>();foreach (var item in s)
{
bytes.Add(new KeyValuePair<string,int>(item+"",Encoding.Default.GetByteCount(item+"")));
}return bytes;
}
//主函数
public static void Main(String[] args)
{
string s = "我是I";foreach (var item in GetCharBytes(s))
{
Console.WriteLine(item.Key+"<===>"+item.Value);
}
}}
如果你有其它意见或私下交流,请发送邮件到:maledong@qq.com;或者请QQ我
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 Cookie Luo 2011年6月2日 8:35