web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Hosk's Dynamic CRM Blog / removing newline and other ...

removing newline and other special characters from a string

Hosk Profile Picture Hosk

If you are a regular follower of my blog you will have no doubt worked out I am doing some development over the last week and have been wrestling with various problems.

Today I found one of my columns had special characters such as Newline, carrage return etc and I wanted to remove them.  In the end I had to make this function and it did the job just fine.  I’m sure I have come across this problem before and I thought I had a better solution but searching on google and I couldn’t find anything.

 

   public static string ReplaceNewlines(string blockOfText, string replaceWith)
        {
            return blockOfText.Replace("\r\n", replaceWith).Replace("\n", replaceWith).Replace("\r", replaceWith).Replace("\t", replaceWith);
        }

Filed under: .NET, Development

This was originally posted here.

Comments

*This post is locked for comments