我有一个windows phone应用程序。在应用程序中,我有一个文本框,它的acceptsreturn属性被设置为true。
我想要做的是从文本框中创建一个字符串,并用一个特定的字符替换新行,比如"NL"
我试过以下几种方法,但都不管用。
string myString = myTextBox.Text.Replace(Environment.NewLine,"NL");
string myString = myTextBox.Text.Replace("\n","NL");发布于 2013-03-05 18:07:53
我不熟悉windows phone(或silverlight),但可以尝试使用\r:
string myString = myTextBox.Text.Replace("\r","NL");Why does a Silverlight TextBox use \r for a newline instead of Environment.Newline (\r\n)?
发布于 2013-03-05 18:08:21
考虑替换不同类型的换行符,以处理所有可能的情况
string myString myTextBox.Replace("\r\n", "NL").Replace("\n", "NL").Replace("\r", "NL");发布于 2013-03-05 18:11:21
使用此代码
var myString = myTextBox.Text.Replace("\r","NL");这是为了与所有操作系统兼容。
https://stackoverflow.com/questions/15220939
复制相似问题