Hello folks,
When I hear from one of my friend, that he needs to convert HTML text to Plain Text. I thought let me checkout this on Microsoft dynamics AX. I start searching out and there is no straightforward way to do this in Dynamics AX (No class or method to do this) then I decide to make my own.
Here is a small piece of code which going to help you out to convert you HTML text to Text. This can be your email text, which need to stop in text file or could be to show on any field.
Comment below if this saved your time and helped.
This comment has been removed by a blog administrator.
ReplyDeleteif you need to survive
ReplyDeletestatic public str Html2Text(str _htmlStrFormat)
{
System.Text.RegularExpressions.Regex regex,lineBreakRegex,stripFormattingRegex,tagWhiteSpaceRegex;
System.Text.RegularExpressions.RegexOptions regexOptions;
str text = '';
str tagWhiteSpace,stripFormatting,lineBreak;
str htmlStrFormat = _htmlStrFormat;
tagWhiteSpace = @"(>|$)(\W|\n|\r)+<";
stripFormatting = @"<[^>]*(>|$)";
lineBreak = @"<(br|BR)\s{0,1}\/{0,1}>";
lineBreakRegex = new System.Text.RegularExpressions.Regex(lineBreak,System.Text.RegularExpressions.RegexOptions::Multiline);
stripFormattingRegex = new System.Text.RegularExpressions.Regex(stripFormatting,System.Text.RegularExpressions.RegexOptions::Multiline);
tagWhiteSpaceRegex = new System.Text.RegularExpressions.Regex(tagWhiteSpace,System.Text.RegularExpressions.RegexOptions::Multiline);
text = htmlStrFormat;
text = System.Net.WebUtility::HtmlDecode(text);
text = tagWhiteSpaceRegex.Replace(text,"><");
text = lineBreakRegex.Replace(text,"\n");
text = stripFormattingRegex.Replace(text,'');
return text;
}
This comment has been removed by a blog administrator.
ReplyDeleteIt was a great information and Its really worth reading it.
ReplyDeleteD365 AX Online Training