多行文本取段落文字

本文介绍如何在ASP.NET中处理多行文本框(TextBox)的内容,通过Button点击事件,提取并显示文本框内的段落。示例代码展示了如何利用字符串操作方法获取文本段落。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="145px"
        Width="279px"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

  1. protected void Button1_Click(object sender, EventArgs e)
  2.         {
  3.             //Response.Write(this.TextBox1.Text);
  4.             string s = this.TextBox1.Text.Trim(); 
  5.             string temp = "";
  6.             int count = 1;
  7.             if (s.Contains("/r/n"))
  8.             {
  9.                 while (true)
  10.                 {
  11.                     if (!s.Contains("/r/n"))
  12.                     {
  13.                         Response.Write("temp " + count + " == >" + s);
  14.                         break;
  15.                     }
  16.                     temp = s.Substring(0, s.IndexOf("/r/n", 0));
  17.                     if (temp == "")
  18.                     {
  19.                         s = s.Remove(0, temp.Length + 2);
  20.                         continue;
  21.                     }
  22.                     Response.Write("temp " + count + " ==> " + temp + "<br/>");
  23.                     s = s.Remove(0, temp.Length + 2);
  24.                     count++;
  25.                 }
  26.             }
  27.             else
  28.             {
  29.                 Response.Write("temp " + count + " ==> " + s);
  30.             }
  31.         }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值