How to Replace the generic css style into empty string using C#

Tags: c#,css,replace

Problem :

When i take a list of items from one list, some css styles are added into that. I want to remove / Replace that. The following code is used to replace the style generic. But it is not given the result.

flag.Text = flag.Text.Replace("style=[\"'](.*)[\"']", "");

But it is not replacing. How to give this. Or shall i use Contains method?

Solution :

You probably want to try using Regex.Replace (and using Multiline option, just in case) instead of string.Replace:

RegexOptions options = RegexOptions.Multiline; 
flag.Text = Regex.Replace(flag.Text, "style=[\"'](.*)[\"']", "", options);

What you show above is Replace using string.Replace. It tries to find exact match of the static text instead of text with pattern. If you want to replace text with pattern, use Regex.Replace instead.

    CSS Howto..

    how to get text aligned vertically with text in list using css

    How do I get
    margin working?

    how to use CSS positioning in 100% width layout

    How to Over ride youtube external style?

    CSS Overflow: overlay. Is it deprecated? How can I replace it?

    How to apply css on checkbox when it's getting disabled?

    How to show different logo on different pages in wordpress theme?

    CSS: how to create a fixed top header with a fixed width

    How to add more items to the list without going to the next row? [closed]

    How do I hide the li's that don't fit on a single line?

    CSS: How do you keep this Div to the right of a float?

    How to get an automatic effect of rosace in css ?

    How am I supposed to change the Bootstrap CSS properties in a new Yeoman project?

    Show and Hide option for DIV(needs modification)

    How to select not first tr and not last td

    Why jQuery.css does not apply a property if it is not supported and how is this being checked?

    How to limit a transform scale to the width and height of the parent element in CSS?

    How can I attach a method to an object to change CSS

    how to prevent css animation from running on page load

    How to export only the used css from a site?

    Handle text as elements, how to hide with CSS?

    Styling the input type=“file”. How do i display the filepath?

    Attempting to show logo using 'content' from CSS

    How to handle the html and css of one side image and other side content and vice versa

    How to proportionally fit a variable number fieldsets inside a parent div

    I was wondering how I would make an image appear when I hover over another image [closed]

    How to align the navigation menu in wordpress?

    CSS: how to put one image and one block with two

    in one line not using float

    How to center align the text?CSS

    CSS How to keep page centered, but still put stuff where I want