C#正则表达式判断程序路径是否存在中文字符

428
补充展位 Pages_Weblog_Get#0
文章摘要
此内容由人工摘要内容,并由AI根据文章内容进行润色
暂无内容

C# 如何判断程序路径是否存在中文字符

有些软件(比如某些国外的专业软件或者开源组件) 一旦安装路径中存在中文 就会出现莫名奇妙的问题,所以用到了同类型软件或组件集成的程序运行前最好做一下中文判断

实现代码如下:

string ProgramPath = AppDomain.CurrentDomain.BaseDirectory;  
string pattern = "[\u4e00-\u9fbb]";  
bool IncludingChinese = System.Text.RegularExpressions.Regex.IsMatch(ProgramPath, pattern);  
if (IncludingChinese)  
{  
    MessageBox.Show("程序安装目录 不允许存在中文!", "启动异常风险提   示",MessageBoxButton.OK,MessageBoxImage.Asterisk);  
    this.Shutdown(); //直接结束程序
    return;  
}
补充展位
Pages_Weblog_Get#439f4665-f145-4f34-8516-3c604bad7afe
补充展位 Pages_Weblog_Get#1
补充展位 Pages_Weblog_Get#2
专题推荐
暂无内容
补充展位 Pages_Weblog_Get#3