using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "中国语言文学系";
// 按分号分割
string[] words = str.Split(';');
string result = string.Empty;
for (int i = 0; i < words.Length; i++)
{
if (!string.IsNullOrEmpty(words[i]))
{
// 转换前,去除每个单词前
result += (char)Convert.ToInt32((words[i].Remove(0, 2)));
}
}
// 输出
Console.WriteLine(result);
}
}}
string str ="中国";
System.Text.RegularExpressions.Regex reg
=new System.Text.RegularExpressions.Regex("(\\d+);");
System.Text.StringBuilder builder=new StringBuilder();
foreach (System.Text.RegularExpressions.Match element in reg.Matches(str)) {
builder.Append((char)int.Parse(element.Groups[1].Value));
}
string str1=builder.ToString();
Debug.WriteLine(str1);
如果是在web 环境,直接用 Server.HtmlDecode 就可以了。。。
如果不是在 web 环境,调用 HttpUtility.UrlDecode() ,在 System.Web 命名空间下。
如果没有,就引用一下 System.Web 程序集