Remove HTML tags from string in c#

Remove HTML tags from string. Somewhere we need to parse some string which is received by some responses like Httpresponse from the server.


So we need to parse it.


Here I will show how to remove html tags from string.

        // sample text with tags

        string str = "<html><head>sdfkashf sdf</head><body>sdfasdf</body></html>";


        // regex which match tags

        System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("<[^>]*>");


        // replace all matches with empty strin

        str = rx.Replace(str, "");


        //now str contains string without html tags



Next Recommended Reading Return String Function in C#.Net