if (current < 127)
target.Text += current;
else
{
target.Text += "&#";
string code = ((int)current).ToString();
target.Text += code;
target.Text += ";";
}
target.Text += current;
else
{
target.Text += "&#";
string code = ((int)current).ToString();
target.Text += code;
target.Text += ";";
}
的意思是,判断current这个字符是不是一个ascii字符,比如英文数字等,如果是ascii字符,则直接加入target.Text中,下面的else是处理current不是英文数字标点的情况,比如是汉字的一部分时,则把它转化为转义符,应该是html,
不好意思,没把代码发齐private void copyClick(object sender, RoutedEventArgs e)
{
target.Text = "";
string from = source.Text;
for (int i = 0; i != from.Length; i++)
{
char current = from[i];
copyOne(current);
}
} private void copyOne(char current)
{
switch (current)
{
case '<':
target.Text += "<";
break;
case '>':
target.Text += ">";
break;
case '&':
target.Text += "&";
break;
case '\"':
target.Text += """;
break;
case '\'':
target.Text += "'";
break;
default:
if (current < 127)
target.Text += current;
else
{
target.Text += "&#";
string code = ((int)current).ToString();
target.Text += code;
target.Text += ";";
}
break;
}
else里面为什么不能写target.Text += "&#" + current + ";";
target.Text += current;//target的文本值追加current的值
else//否则
{
target.Text += "&#";//target的文本值追加"&#"
string code = ((int)current).ToString();//强转current为int类型,然后 再转为string类型并赋值给code
target.Text += code;//traget文本值追加Code的值
target.Text += ";";//target文本值追加";"
}
我意思这些数字既然不是ascii码的序号,那是什么码的呢