Argentini.Halide.H3Text.ConvertLinefeeds C# (CSharp) Method

ConvertLinefeeds() public static method

or

tags, except between [nofeed][/nofeed] tags. ]]>
public static ConvertLinefeeds ( string strVar, string feedType ) : String
strVar string String to convert.
feedType string /// " or "

". /// ]]> ///

return String
        public static String ConvertLinefeeds(string strVar, string feedType)
        {
            if(strVar.Length < 1) return (String.Empty);

            int checkRET = 0;
            int checkLF = 0;
            int checkNoFeed = 0;
            Regex regex = null;
            MatchCollection theMatches = null;

            string final = strVar;

            if(InStr(final, "/nofeed>") > 0) checkNoFeed = 1;
            if(InStr(final, "/nofeed]") > 0) checkNoFeed = 2;

            if(checkNoFeed == 1)
            {
                regex = new Regex(@"<nofeed>(.*?)</nofeed>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                theMatches = regex.Matches(strVar);

                for (int index = 0; index < theMatches.Count; index++)
                {
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace("\r", "[[[pk:return]]]"));
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace("\n", "[[[pk:linefeed]]]"));
                }
            }

            if(checkNoFeed == 2)
            {
                regex = new Regex(@"\[nofeed\](.*?)\[/nofeed\]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                theMatches = regex.Matches(strVar);

                for (int index = 0; index < theMatches.Count; index++)
                {
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace("\r", "[[[pk:return]]]"));
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace("\n", "[[[pk:linefeed]]]"));
                }
            }

            if(InStr(final, "\r") > 0)
            {
                checkRET = 1;

                final = final.Replace("\n", "");

                if(feedType == "<p>")
                {
                    final = final.Replace("\r", "</p><p>");
                }
                else
                {
                    final = final.Replace("\r", "<br />");
                }

            }
            else
            {
                if(InStr(final, "\n") > 0)
                {
                    checkLF = 1;

                    final = final.Replace("\r", "");

                    if(feedType == "<p>")
                    {
                        final = final.Replace("\n", "</p><p>");
                    }
                    else
                    {
                        final = final.Replace("\n", "<br />");
                    }
                }
            }

            if(feedType == "<p>")
            {
                final = "<p>" + final;

                if(Right(final, 3) == "<p>")
                {
                    final = Left(final, final.Length - 3);
                }
                else
                {
                    if(InStr(final, "</p><p>") > 1)
                    {
                        final += "</p>";
                    }
                }
            }

            if(checkRET == 1) final = final.Replace("[[[pk:return]]]", "\r");
            if(checkLF == 1) final = final.Replace("[[[pk:linefeed]]]", "\n");

            return final;
        }