Asp.net 如何接受多行文本并将其更改为单线?
我想使我的文本框能够从粘贴功能接收多行文本,并将其更改为单行,如下例所示:Asp.net 如何接受多行文本并将其更改为单线?,asp.net,Asp.net,我想使我的文本框能够从粘贴功能接收多行文本,并将其更改为单行,如下例所示: i want to change this multiline text just into single line. please help 进入 我试图将文本模式改为单线模式,但结果只占用了第一行。我该怎么做?下面是我的代码。非常感谢 <asp:Textbox id="Textbox" TextMode="MultiLine" CssClass="LongTextBox" Width="370px" Runa
i want to change
this multiline text
just into single line.
please help
进入
我试图将文本模式改为单线模式,但结果只占用了第一行。我该怎么做?下面是我的代码。非常感谢
<asp:Textbox id="Textbox" TextMode="MultiLine" CssClass="LongTextBox" Width="370px" Runat="server" AutoCompleteType="Disabled" autocomplete="off" AutoPostBack="true"></asp:Textbox>
您可以用空格替换换行符
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(" ", " ");
或者甚至:
string value=TextBox1.Text.Replace(“\r”,”).Replace(“\n”,”).Replace(“\n”,”).Replace(“\n”,”)代码>。也就是说,修剪回车符,用空格替换空格+换行符,然后用空格替换换行符+空格,然后用空格替换剩余的单个换行符。大小写空格+换行符+空格留给读者作为练习:-)值得考虑使用Environment。换行符代替“\r\n”。
string value = TextBox1.Text.Replace("\r\n", " ").Replace(" ", " ");