我有一个字符串:
"<a href="/departments/Attachments/2043_3162016062557_test1_Health%20Check%20Assessment.docx">SharePoint_Health Check Assessment.docx</a><br><a href="/departments/Attachments/2043_3162016062557_Test2%20W.docx">Test2.docx</a><br>"
我如何修剪它才能得到文字:
/departments/Attachments/2043_3162016062557_test1_Health%20Check%20Assessment.docx
/departments/Attachments/2043_3162016062557_Test2%20W.docx
我只需要网址的文字。
答案 0 :(得分:1)
答案 1 :(得分:0)
string s = "<a href="/departments/Attachments/2043_3162016062557_test1_Health%20Check%20Assessment.docx">SharePoint_Health Check Assessment.docx</a>"
int start = s.IndexOf("href=") + 5;
int end = s.IndexOf("/"", start);
string result = s.SubString(start, end - start);
没有HTML解析库或使用IndexOf和Substring的RegEx是最简单的方法。 注意:未经测试,使用iPhone编写。