字符替换

 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 += "&lt;";
                    break;
                case '"':
                    target.Text += "&#34;";
                    break;
                default:
                    target.Text += current;
                    break;
            }
If opportunity doesn’t knock, build a door
原文地址:https://www.cnblogs.com/CandiceW/p/4204566.html