由于 WPhone 中的 UIElements 有 2048x2048 像素
限制,我试图拆分太长而无法显示的字符串。
我已经尝试实现 ScrollableTextBlock
done here但没有成功。所以我正在努力以另一种方式做到这一点。
我试过在文本中使用通配符,特别是 \r\n
:当它到达时,方法 Splitter
完成 Regex
返回剩余的子字符串:
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);
}
但它在达到 matches[count]
时给了我 ArgumentIsNullException。
我该如何解决?
最佳答案
我认为您可能只需要对您的论点和 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);
}
关于c# - 在 Windows Phone 中将字符串拆分为多个文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29308747/