我想让我的文本框能够从粘贴功能接收多行文字并将其更改为单行,如下例所示:
i want to change
this multiline text
just into single line.
please help
进入
i want to change this multiline text just into single line. please help
我尝试将 textmode 更改为单行但最终只取第一行。我怎样才能做到这一点?以下是我的代码。非常感谢!
<asp:Textbox id="Textbox" TextMode="MultiLine" CssClass="LongTextBox" Width="370px" Runat="server" AutoCompleteType="Disabled" autocomplete="off" AutoPostBack="true"></asp:Textbox>
答案 0 :(得分:3)
您可以用空格替换换行符。
string value = Textbox1.Text.Replace("\r\n", " ");
但是如果文本在换行符之前或之后已经包含空格,那么你将获得2个空格。
i want to change
this multiline text
just into single line.
please help
所以你也可以这样做
string value = TextBox1.Text.Replace("\r\n", " ").Replace(" ", " ");