問題:
string[] sArray = html.Split(new char[2] { '<h1>', '</h1>' });
原因:
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#截取字符串的方法小結