Use RegularExpressions to remove HTML tag strings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.