html文本怎么转化为数字html,将阿拉伯数字转换为html文件中的阿拉伯/波斯数字...

您可以使用正则表达式查找“​​>”之间的HTML部分和'

// Convert all English digits in a string to Arabic digit equivalents

public static string ToArabicNums(string src)

{

const string digits = "۰۱۲۳۴۵۶۷۸۹";

return string.Join("",

src.Select(c => c >= '0' && c <= '9' ? digits[((int)c - (int)'0')] : c)

);

}

// Convert all English digits in the text segments of an HTML

// document to Arabic digit equivalents

public static string ToArabicNumsHtml(string src)

{

string res = src;

Regex re = new Regex(@">(.*?)

// get Regex matches

MatchCollection matches = re.Matches(res);

// process in reverse in case transformation function returns

// a string of a different length

for (int i = matches.Count - 1; i >= 0; --i)

{

Match nxt = matches[i];

if (nxt.Groups.Count == 2 && nxt.Groups[1].Length > 0)

{

Group g = nxt.Groups[1];

res = res.Substring(0, g.Index) + ToArabicNums(g.Value) +

res.Substring(g.Index + g.Length);

}

return res;

}这并不完美,因为它根本不检查标记之外的HTML字符说明符,例如构造;(۱表示1等)以通过Unicode值指定字符,并将替换这些中的数字。它也不会在第一个标签之前或最后一个标签之后处理任何额外的文本。

样品:

Calling: ToArabicNumsHtml("

I was born in 1988

")

Result: "

I was born in ۱۹۸۸

"在ToArabicNums中使用您喜欢的任何代码进行实际转换,或通过传入转换函数对其进行概括。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值