问题:

string[] sArray = html.Split(new char[2] { '<h1>', '</h1>' });

C# Split 字符文本中的字符太多

原因:

Split()里面是用char类型不是string字符串类型,所以只能用一个字符,必须先把多个字符替换成一个字符,然后再分割。

解决方案一:

string html = "<dd><h1> 第二百三十六章 古神精神印记</h1></dd>";
html = html.Replace("<h1>","*").Replace("</h1>","*");
string title = html.Split('*')[1]; // 第二百三十六章 古神精神印记

解决方案二:

string title = html.Split(new string[] { "<h1>", "</h1>" }, StringSplitOptions.RemoveEmptyEntries)[1];

 


相关文章:C#截取字符串的方法小结

 

相关文章:

  • 2021-06-09
  • 2021-08-02
  • 2021-12-21
猜你喜欢
  • 2021-06-08
  • 2021-06-29
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
相关资源
相似解决方案