Since there's the 2048x2048 pixel limit for UIElements in WPhone, I'm trying to split a string that is too long to be shown.
I've tried implementing the ScrollableTextBlockdone here but to no success. So I'm struggling to do it in another way.
I've tried using a wildcard in the text, specifically \r\n: when it's reached, a method Splitter done with Regex returns the remaining substring:
private string Splitter(string str1)
{
MatchCollection matches = Regex.Matches(str1,"\r\n");
int count = matches.Count / 2; //i want to split every text in half avoiding word truncating,
//so I'm getting the NewLine closest to the middle of the text
int pos= matches[count].Index; //I get the index of the char in str1
return str1.Substring(pos);
}
But it gives me the ArgumentIsNullException when reaching matches[count].
How can I resolve this?
I think you may just need some validation on your argument and on matches.Count:
private static string Splitter(string str1)
{
if (string.IsNullOrWhiteSpace(str1)) return str1;
MatchCollection matches = Regex.Matches(str1, "\r\n");
if (matches.Count == 0) return str1;
int count = matches.Count / 2;
int pos = matches[count].Index;
return str1.Substring(pos);
}
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