find replace in c# with a certain character.

Jun 2, 2008
163
0
0
I have a issue with extracting some cells from c#.

When I open what I make in excel, the csv does some new lines or something and causes excel not to do CSV correctly.

I opened the file in wordpad and I found that there are some box characters [] < Like that but a full box.

So I did a find/replace and I was able to get rid of them and it opened in excel with correct formatting.

Does that [] mean it's a newline character?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Not likely, your best bet is to open it up with a Hex Editor and see what binary value is stored there, and translate that to a character to try and figure out what's getting put there instead.

Although, it's probably just easier to find the bug in your code :)
 

Snapster

Diamond Member
Oct 14, 2001
3,916
0
0
Could be a single/double carriage return without a line feed or could be a Unicode character.
 

GoatMonkey

Golden Member
Feb 25, 2005
1,253
0
0
So, you have a text file that is comma separated values with some unwanted characters in there, is that right?

What you need to fix that is to open the file as a Textreader and read each line as a string. You can then do a simple string replace and write a new file from that.

int counter = 0;
string line;

// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");
while ((line = file.ReadLine()) != null)
{
line.Replace("[]", "");
Console.WriteLine(line);
counter++;
}

file.Close();

// Suspend the screen.
Console.ReadLine();

Sample from Microsoft:
http://msdn.microsoft.com/en-u...y/aa287535(VS.71).aspx