is there an equivalent to .Lines of winForms in WPF?
I'm using this currently:
var textRange = new TextRange(TextInput.Document.ContentStart, TextInput.Document.ContentEnd);
string[] lines = textRange.Text.Split('\n');
RichTextBox is a FlowDocument type and that does not have a Lines property. What you are doing seems like a good solution. You may want to use IndexOf instead of split.
You can also add an extension method like the article suggests:
public static long Lines(this string s)
{
long count = 1;
int position = 0;
while ((position = s.IndexOf('\n', position)) != -1)
{
count++;
position++; // Skip this occurance!
}
return count;
}
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