Omarrrio
Omarrrio

Reputation: 1142

How to replace an actual "\n" string, not the line break escape

I've been trying for the last two hours, but i can't replace the string \n, this is what i did:

Encoding enc = Encoding.ASCII;
for (int i = 0; i < numpntr; i++)
{
    bw.BaseStream.Position = strt + i*var;
    bw.Write(
        enc.GetBytes(listView1.Items[i].SubItems[1].Text.Replace("\n","\x0A") + (new string('\0',
            bytecnt - enc.GetByteCount(listView1.Items[i].SubItems[1].Text.Replace("\n" + "\x0A"))))));
}
bw.Flush();
bw.Close();
bw = null;

is there anyway to replace it as a string ?

Upvotes: 0

Views: 162

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101681

You could use " \\n " or you can put ' @ ' begining of your string like this:

enc.GetBytes(listView1.Items[i].SubItems[1].Text.Replace(@"\n" + "\x0A")

They are called verbatim strings, you can take a look at this documentation.

Upvotes: 5

Related Questions