I wrote a regular expression myself, <(.|n)+?>
This is to replace all HTML tags, non-greedy, multi-line.
If I want to replace all non-HTML tags,
My code can only be like this, first find the HTML tag, and then replace the tag.
Can I find non-HTML tags directly? .
There is another problem, intercepting the length of the string.
The method I used below does not determine whether it is Chinese or non-Chinese. The intercepted length is always longer or shorter.
I don’t know if there is a better way to make the intercepted length the same length, instead of the length of str.Length.
public static string formatString(string str, int size) { string temp = str; Regex regex = new Regex("<.+?>"); temp = regex.Replace(str, ""); temp = temp.Replace("\r\n", ""); temp = temp.Replace(" ", ""); if (temp.Length >= size) { temp = temp.Substring(0, size - 3) + " "; } return temp; }