Commit e20c1059 LN

1

1 个父辈 53debe60
......@@ -164,6 +164,7 @@ namespace CodeLibrary
foreach (CodeInfo code in list)
{
txtResult.Text += "\r\n" + "" + code.CodeType + " (X:" + code.X + ",Y:" + code.Y + ") " + code.CodeStr;
txtResult.Text += "\r\n" + "" + code.CodeType + " (X:" + code.X + ",Y:" + code.Y + ") " + code.GetCodeStr();
}
}
else
......
......@@ -6,6 +6,7 @@ using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CodeLibrary
......@@ -332,5 +333,41 @@ public class CodeInfo
this.X = x;
this.Y = y;
}
public string GetCodeStr()
{
return Gb2312Correct(CodeStr);
}
/// <summary>
/// 判断字符串中是否包含中文
/// </summary>
/// <param name="str">需要判断的字符串</param>
/// <returns>判断结果</returns>
public static bool HasChinese(string str)
{
return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
}
/// <summary>
/// utf8文字用gb2312格式显示时候乱码,需要转换为gb2312
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Gb2312Correct(string text)
{
if (HasChinese(text) == false)
{
return text;
}
//声明字符集
System.Text.Encoding utf8, gb2312;
//utf8
utf8 = System.Text.Encoding.GetEncoding("utf-8");
//gb2312
gb2312 = System.Text.Encoding.GetEncoding("gb2312");
byte[] gb;
gb = utf8.GetBytes(text);
gb = System.Text.Encoding.Convert(utf8, gb2312, gb);
//返回转换后的字符
return gb2312.GetString(gb);
}
}
}
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using ZXing;
using ZXing.Common;
......@@ -202,6 +203,8 @@ namespace CodeLibrary
}
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!