This is a text editor. I am trying to open a new file and if the existing file is not empty, users get a warning to save the file or not. But if I use the condition if (text== "")
, the value of text still has "\r\n"
new line value. Even I didn't click on the text area.
Why does string get the value of the new line? It doesn't have to be empty?
private void New_Click(object sender, RoutedEventArgs e)
{
var text = new TextRange(richtxtbox.Document.ContentStart, richtxtbox.Document.ContentEnd).Text;
if (text == "")
{
MainWindow newWindow = new MainWindow();
newWindow.Show();
Window.GetWindow(this).Close();
}
else
{
// ...
}
}
I have to do this:
if (text == "" || text == "\r\n")
{
MainWindow newWindow = new MainWindow();
newWindow.Show();
Window.GetWindow(this).Close();
}