I am pulling data from a database that uses ascii character 254 as a delimiter. I want to replace that with a new line.
I tried this:
rec = rec.Replace(char(254), Environment.NewLine);
This isn't working though.
I am pulling data from a database that uses ascii character 254 as a delimiter. I want to replace that with a new line.
I tried this:
rec = rec.Replace(char(254), Environment.NewLine);
This isn't working though.
It seems like your char assignment is wrong:
rec = rec.Replace((char)254, Environment.NewLine);
just realized there's a type mismatch on that line, too. Here's the code without the mismatch:
rec = rec.Replace("" + (char)254, Environment.NewLine);
Char() is not a constructor for characters. You need to cast a number as a character, there is no equivalent to the VB.NET Chr() function in C#.
Try something like this:
rec = rec.Replace( (String) ((char) 254), Environment.NewLine);
Edit: String.Replace does not have an overload for (char,string) and NewLine can be multiple characters, so I added another cast to string just to be explicit. (Gonzalo, you caught me during my edit! lol)
Use this:
rec = rec.Replace ('\xFE', '\n');
or this:
rec = rec.Replace ("\xFE", Environment.NewLine);
Assuming what you have won't compile, try this:
rec = rec.Replace( ((char)254).ToString(), Environment.NewLine);
Environment.NewLine is a string... you can only replace a char with a char, or a string with a string.
You could try this:
rec = rec.Replace("" + (char)254, Environment.NewLine);