Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a HTML String like

<P style="MARGIN-BOTTOM: 12px; TEXT-ALIGN: center; MARGIN-LEFT: 0px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Verdana'; FONT-WEIGHT: normal; FONT-STYLE: normal">Automate to streamline your business process</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Verdana'; FONT-WEIGHT: normal; FONT-STYLE: normal">Streamlining the entire insurance process workflow</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Verdana'; FONT-WEIGHT: normal; FONT-STYLE: normal">Powerful reporting that meets all Federal Standards</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Arial Black'; FONT-WEIGHT: normal; FONT-STYLE: normal">Data flow among different business areas</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Arial Black'; FONT-WEIGHT: normal; FONT-STYLE: normal">Savings on time‚ cost and resources</SPAN></P>



i Want to process this HTML string
and want a output like

<P style="MARGIN-BOTTOM: 12px; TEXT-ALIGN: center; MARGIN-LEFT: 0px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Verdana' !mportant; FONT-WEIGHT: normal; FONT-STYLE: normal">Automate to streamline your business process</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Verdana' !mportant; FONT-WEIGHT: normal; FONT-STYLE: normal">Streamlining the entire insurance process workflow</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Verdana' !mportant; FONT-WEIGHT: normal; FONT-STYLE: normal">Powerful reporting that meets all Federal Standards</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Arial Black' !mportant; FONT-WEIGHT: normal; FONT-STYLE: normal">Data flow among different business areas</SPAN></P>
<P style="MARGIN-BOTTOM: 12px; MARGIN-TOP: 0px; LINE-HEIGHT: 1.1499; MARGIN-RIGHT: 0px"><SPAN style="FONT-SIZE: 16px; FONT-FAMILY: 'Arial Black' !mportant; FONT-WEIGHT: normal; FONT-STYLE: normal">Savings on time‚ cost and resources</SPAN></P>



I want to add !important in Each Font-Family Attribute of CSS .

How can i accomplish this.

Thanks
Posted
Updated 18-Jun-14 1:23am
v2
Comments
Thanks7872 18-Jun-14 7:18am    
So we are suppose to compare these both code dumps? I have not seen the above code,but from what i understand, you can loop through each span in the above code using JQuery and replace the CSS attribute with whatever value you like.

1 solution

Use a regex:
C#
public static Regex regex = new Regex(
      "(?<=FONT-FAMILY:\\s)(?<Font>'.+')(?=;)",
    RegexOptions.IgnoreCase
    | RegexOptions.Multiline
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );
public static string regexReplace = "${Font} !mportant";

// Replace the matched text in the InputText using the replacement pattern
string result = regex.Replace(InputText,regexReplace);


Revised version:
C#
public static Regex regex = new Regex(
      "(?<=FONT-FAMILY:\\s)(?<Font>'.+?')(?=;)",
    RegexOptions.IgnoreCase
    | RegexOptions.Multiline
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );
public static string regexReplace = "${Font} !mportant";

// Replace the matched text in the InputText using the replacement pattern
string result = regex.Replace(InputText,regexReplace);
 
Share this answer
 
v2
Comments
PKriyshnA 18-Jun-14 7:31am    
Thanks a lot.
OriginalGriff 18-Jun-14 7:48am    
You're welcome.
PKriyshnA 18-Jun-14 8:14am    
Not Working With this string

Please suggest.


<p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;">
<span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">This chapter describes how to address globalization and localization issues in Web applications. The chapter includes the following sections:</span></p><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 24px;">Understanding Globalization and Localization Issues</span></p><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">Using Cultures</span></p><p style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">Formatting Data</span></p><p style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">Creating Localized Resources</span></p><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">Applications mi</span><span style="font-family: 'Calibri';font-style: Normal;font-weight: normal;font-size: 16px;color: #FF0000;">ght be used in multiple geographical locations and cultures; this can bring many challenges to software architects, particularly when designing the presentation layer. This chapter describes how to address these challenges so that your applications can support as broad a customer base as possible. This chapter also describes how to design and implement your applications so that they can be easily extended to support new cultures when nec</span><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">essary.</span></p><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">For a summary of best practices and recommendations discussed in this chapter, see "Best Practices for Developing World-Ready Applications" on MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconbestpracticesforglobalapplicationdesign.asp).</span></p><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">Understanding Globalization and Localization Issues</span></p><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">Globalization is the term given to the process of making sure that an application does not contain any internal dependencies on a particular culture; for example, it is best for a globalized application to not have any hard-coded number formats that can differ across multiple countries, or to assume a particular sorting mechanism for strings. A globalized application can correctly accept, process, and display a worldwide assortment of scripts, data formats, and languages.</span></p><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.14999997615814;"><span style="font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;">Localization is the process of adapting an application, and in particular the user interface, to suit a specific culture. Localization typically involves tasks such as translating strings into different natural languages, resizing
OriginalGriff 18-Jun-14 8:35am    
Add a "as few as possible" option:
"(?<=FONT-FAMILY:\\s)(?'.+?')(?=;)"
PKriyshnA 18-Jun-14 9:21am    
By Using given regex getting error like

parsing "(?<=FONT-FAMILY:\s)(?'.+?')(?=;)" - Invalid group name: Group names must begin with a word character.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900