How to emphasize $ 10 and $ 50.58

All customers charge $ 10 from $ 50.58 at ccc.com Home Decor, Home Appliances and an open-air shop! Until 5/31/2012 "

I get the above string type from db, the string may or may not contain $. If it contains $, then the numbers after $ must be underlined. The string is fully dynamic. It may also not contain $

+3
source share
2 answers

Try regex:

Regex.Replace(str, @"(?<=\$)\d+(\.\d+)?", "<u>$0</u>");

Some examples of outputs:

"4.5"     -> "4.5"         (untouched)
"4"       -> "4"           (untouched)
"$4.5"    -> "$<u>4.5</u>"
"$4"      -> "$<u>4</u>"

Although, since it is udeprecated, you should probably consider <span>with a class or inline style with a directive text-decoration: underline:

Regex.Replace(str, @"(?<=\$)\d+(\.\d+)?", 
  "<span style=""text-decoration: underline"">$0</span>");

, : span, , ( "</span>" (3- ) "<span>" )

+7

... , , , - indexOf

        string s = "$10";
        string t =  (s.IndexOf('$') > 0) ? "<span style=\"text-decoration: underline\">#</span>".Replace("#",s):"<span>{0}</span>".Replace("#",s);
0

All Articles