Alex Rivera | Logout

String.Replace(char, char) method in C#

Asked 2009-03-16T18:56:49.433
74

How do I replace \n with empty space?

I get an empty literal error if I do this:

string temp = mystring.Replace('\n', '');
Edit
Report

2 Answers

0

Found on Bytes.com:

string temp = mystring.Replace('\n', '\0');// '\0' represents an empty char

answered 2012-10-11T14:52:40.977
0

I know this is an old post but I'd like to add my method.

public static string Replace(string text, string[] toReplace, string replaceWith)
    {
        foreach (string str in toReplace)
           text = text.Replace(str, replaceWith);

        return text;
    }

Example usage:

string newText = Replace("This is an \r\n \n an example.", new string[] { "\r\n", "\n" }, "");
answered 2013-01-20T19:45:23.607

Your Answer