如何在多行文本框中逐行获取? [英] How to get the line by line in multiline text box?

查看:98
本文介绍了如何在多行文本框中逐行获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,

我正在使用多行文本框获取地址.我想将此地址逐行保存在其他列字段中.怎么做?

例如,我给地址如下

拉曼,
第一街,
钦奈.

像下面这样保存到sql table

Hai,

I am using Multiline Textbox for get Address. I want to save this address to line by line in different column field. How to do it?

For example, I am giving Address like following

Raman,
1st Street,
Chennai.

This is saved like following to sql table

Address1   Address2   Address3
Raman      1st Street Chennai



那么,如何在不同的字符串变量中逐行获取?
请帮助我...



So, How we can get line by line in different string variable?
Please help me...

推荐答案

使用
Split the TextBox''s Text property using the String.Split[^] method, that is:
string[] sep = new string[] {"\r\n"};
string[] lines = textBox.Text.Split(sep, StringSplitOptions.RemoveEmptyEntries);


您将得到一个由string组成的数组,每个数组对应于另一行.


you get an array of strings, each one corresponding to a different line.


您可以使用
You can use Regex.Split()[^] for this.

Example:
string[] lines = Regex.Split(txtAddress.Text, "\r\n");


<asp:textbox id="TextBox1" runat="server" textmode="MultiLine" height="100px" width="300px" :asp="#unknown">
        <asp:button id="Button1" runat="server" text="Button" asp="#unknown" />


这篇关于如何在多行文本框中逐行获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆