1. Demand Scenario
Because of the need to make a push data service, call WebService, for some reason need to use HTTP to send SOAP requests, and the data pushed is in JSON format, in the test process found that the request failed, the server side WebService returned 400 error. Return 400 error, should be the requested data format is not correct, because of my special situation, the requested data must be able to format the XML format, the contents of a node can be correctly formatted as a JSON string, found that the requested data has HTML tags, need to filter out the request.
2. Realization function
Use the RegularExpressions regular expression:
. Matches any single character except "\ n".
* matches the preceding subexpression 0 or more times.
? Matches the preceding subexpression 0 or one time.
Just replace the "<.*?>" of the article with String.Empty.
Code Implementation
using System.Text.RegularExpressions; Public Static string Removehtmltag (string articlestring) { return<.*?> "string. Empty);}
Use RegularExpressions to remove HTML tag strings