Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
All Customers Take $10 off $50 in ccc.com's Home Decor, Home Appliances and Outdoor Store! Valid through 5/31/2012"

I am getting the above string from db,the string may or may not contain $.If it contains $ then the numbers after the $ should be underlined
Posted
Updated 10-May-12 2:16am
v2

You can get the text that you need to wrap up using a regex like this:
C#
public static Regex regex = new Regex(
      "\\$\\d+\\s"
    RegexOptions.CultureInvariant
    | RegexOptions.Compiled
    );
If your numbers become more complex (e.g. $1,299.34) then you'll need to expand your regex, but following the principal of YAGNI I haven't complicated this regex. Simply run the regex and do the replaces as you need.
 
Share this answer
 
v2
C#
using System;
using System.Text.RegularExpressions;

class Test
{
    public static void Main()
    {
        string pattern = @"\$\d+";
        Regex rgx = new Regex(pattern);

        // Here is the string you got from the DB
        string inputStr = "All Customers Take $10 off $50 in ccc.com's Home Decor, Home Appliances and Outdoor Store! Valid through 5/31/2012";

        // Surround the $number matches with spans that will add under line (styled HTML markup)
        string outputStr = rgx.Replace(inputStr, "<span style=\"text-decoration:underline\">$&</span>" );

        // Display the resulting string.
        Console.WriteLine("Pattern:       \"{0}\"", pattern);
        Console.WriteLine("Input string:  \"{0}\"", inputStr);
        Console.WriteLine("Output string: \"{0}\"", outputStr);
    }
}


That should do it. As Pete already mentioned you may have to adjust the pattern to recognize other numbers with decimal separators etc. as well.

Best,

Manfred
 
Share this answer
 
v3
Comments
Pete O'Hanlon 10-May-12 10:42am    
My 5.
XML
what you want from us??? What I understand is that you want to underline the text. solution for this is as below:

All Customers Take $10 off $50 in ccc.com's Home Decor, Home Appliances and Outdoor Store! Valid through 5/31/2012" 


use underline tags of html


make it answer if your problem get solved..
 
Share this answer
 
v3
Comments
Pete O'Hanlon 10-May-12 8:18am    
That's not what the OP asked for. They want only the $10 and $50 to be underlined in this sample.
Tirthankar Dutta 10-May-12 8:20am    
yes that true
AshishChaudha 10-May-12 8:25am    
improved my solution...check it out
Tirthankar Dutta 10-May-12 8:28am    
its not a static string,depending on conditions it may change,so how can I be sure if there is any occurence of $ or no not.If if $ exists then how to underline the number after the $
AshishChaudha 10-May-12 8:30am    
You have to clear your question first...without cleared about your question why you voted me down..

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