user2090762
user2090762

Reputation: 87

How to convert <span style="text-decoration: underline;">Name</span> to "<u>Name</u>"(basic HTML) in ASP.Net for SSRS reports?

I have an issue in converting this tag(<span style="text-decoration: underline;">Name</span>) to (<u>Name</u>) in asp.net.

I need it for SSRS reporting since SSRS reporting does't support styles when "Interpret the HTML tags as styles" is checked.

Note: Name can be anything based on the conditions from the above spam tag and the above script may contains different tags like 'underline,bold,italic' as styles.

Upvotes: 0

Views: 8919

Answers (3)

user2090762
user2090762

Reputation: 87

Also check this and you can make your own changes. https://dotnetfiddle.net/wgHV6p

Upvotes: 0

user2090762
user2090762

Reputation: 87

    string old_str = @"<span style=""font-weight:underline;"">John</span> <span style=""font-style: bold;"">Steve</span><span style=""text-weight:italic;"">Abrahem</span>";        


    string new_str1 = Regex.Replace(old_str, @"<span style=""font-weight:underline;"">(.*?)</span>", new MatchEvaluator(ReplaceUnderline)); 

string new_str2=Regex.Replace(new_str1, @"<span style=""font-style: bold;"">(.*?)</span>", new MatchEvaluator(ReplaceBold)); 

string new_str3=Regex.Replace(new_str2, @"<span style=""text-weight:italic;"">(.*?)</span>", new MatchEvaluator(ReplaceItalic)); 

        Console.WriteLine(new_str3);
    }

    static string ReplaceUnderline(Match m)
        {
    return "<ul>" + m.Groups[1] + "</ul>";
        }
    static string ReplaceBold(Match m)
        {
    return "<b>" + m.Groups[1] + "</b>";
        }

    static string ReplaceItalic(Match m)
        {
    return "<i>" + m.Groups[1] + "</i>";
        }

Upvotes: 3

user2316116
user2316116

Reputation: 6814

In ASP.NET you could use regular expressions.

string old_str = @"<span style=""text-decoration: underline;"">Name</span>";
string new_str = Regex.Replace(old_str, "<.*?>", string.Empty);

Demo: https://dotnetfiddle.net/wWMvpm

To find multiple occurrences

string old_str = @"<span style=""font-weight:underline;"">John</span> <span style=""font-style: underline;"">Steve</span> <span style=""text-decoration: underline;"">Abrahem</span>";
string new_str = Regex.Replace(old_str, "<.*?>(.*?)<.*?>", new MatchEvaluator(Replace)); 

static string Replace(Match m)
{
    return "<ul>" + m.Groups[1] + "</ul>";
}

Demo: https://dotnetfiddle.net/M26VgU

Upvotes: 1

Related Questions