I have the two following code pieces:
private void AddTextToLog(string textToAdd)
{
//Console.WriteLine(@"Raw Text: " + textToAdd);
textToAdd = RemoveInvalidCharacters(textToAdd);
var array = ParseLogText(textToAdd);
foreach (var entry in array)
{
_log.Add(entry);
MainForm.Get.UISynchContext.Send(o => MainForm.Get.AddToChatLog(entry), null);
}
}
And:
public void AddToChatLog(string text)
{
tbChatLog.AppendText("\r\n" + text);
//tbChatLog.AppendText(Environment.NewLine);
}
What happens here is that when AddTextLog(text)
is called, some new text is appended to tbChatLog, which is a textBox.
The weird thing is that, if in do not include \r\n
or Environment.NewLine
in AddToChatLog
method, then all gets added directly after each other, without any line breaks or whitespace. If I add one of those two line break codes, then not only is it dropped to the next line of the textbox, but a whole empty line is added too. So it seems it does two line breaks.
Any idea?
Thanks!
UPDATE:
This is the text without any line-break added:
A710E000A:Simon:1A7110000A:Simon:2A7118000A:Simon:3
If I add a line break of some sort to AddToChatLog
, I get this:
A721F000A:Simon:1
A7222000A:Simon:2
A7223000A:Simon:3
UPDATE 2:
Hmmmm, I added a Console.WriteLine("ENTRY: " + entry)
to the AddTextToLog
method, and turns out every time it adds something in the for loop, there is also an empty entry. That is really bizarre. I got the array from a string.Split method, there should be no empty entries in the array...
SOLUTION:
I was Split'ing on a certain set of characters, which as it turns out the master-string could start with. If you split at the start of a string you actually get a string array with one empty string at top. Two fixes that both work: One was stripping empty array entries with Linq. The other, which is easier, is just to create a Substring from the master string, that starts a few characters in, so split does not happen at the start of the master-string.
Thanks for all the help!