我正在尝试将纯文本阿拉伯数字转换为东阿拉伯数字。所以基本上取1 2 3...并将它们转换为١ ٢ ٣...。该函数转换所有数字,包括标签中包含的任何数字,即H1
.
private void LoadHtmlFile(object sender, EventArgs e)
{
var htmlfile = "<html><body><h1>i was born in 1988</h1></body></html>".ToArabicNumber(); ;
webBrowser1.DocumentText=htmlfile;
}
}
public static class StringHelper
{
public static string ToArabicNumber(this string str)
{
if (string.IsNullOrEmpty(str)) return "";
char[] chars;
chars = str.ToCharArray();
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= '0' && str[i] <= '9')
{
chars[i] += (char)1728;
}
}
return new string(chars);
}
}
我还尝试仅针对 InnerText 中的数字,但它也没有工作。下面的代码也更改了标签号。
private void LoadHtmlFile(object sender, EventArgs e)
{
var htmlfile = "<html><body><h1>i was born in 1988</h1></body></html>" ;
webBrowser1.DocumentText=htmlfile;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Body.InnerText = webBrowser1.Document.Body.InnerText.ToArabicNumber();
}
有什么建议么?