private void tbLog_TextChanged(object sender, TextChangedEventArgs e)
{
//Get only NEW text added to Log
}
/*
LOG
old message...
old message...
old message...
old message...
NEW message...
NEW message...
NEW message...
NEW message...
NEW message...
*/
How to I get only NEW text from the TextBox?
Perhaps you should be using the TextChangedEventArgs.Changes property:
var fullText = tbLog.Text;
if (e.Changes.Any())
{
var additions = e.Changes.Where(tc => tc.AddedLength > 0);
var newTexts = additions.Select(tc => fullText.Substring(tc.Offset, tc.AddedLength));
// TODO: Do stuff with the new pieces of text
}
Something like this?
private string old_text = "";
private void tbLog_TextChanged(object sender, TextChangedEventArgs e)
{
if(old_text != tbLog.Text)
{
writeLog(tbLog.Text);
old_text = tbLog.Text;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With