Click here to Skip to main content
15,879,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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

1st Street,

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);

you get an array of strings, each one corresponding to a different line.
Share this answer
devausha 9-May-12 5:24am    
Thank you,It is working. I want to set multiline textbox to Limited 3 lines.
So I give 3 for Rows Properties. But it is not working. Please help me
Member 10506786 22-Apr-16 14:41pm    
this only works if the original text contains "\r\n". But is it is a long single string without new line characters, multiline textbox still wraps it - how to get wrapped lines in this case?
You can use Regex.Split()[^] for this.

string[] lines = Regex.Split(txtAddress.Text, "\r\n");
Share this answer
<asp:textbox id="TextBox1" runat="server" textmode="MultiLine" height="100px" width="300px" :asp="#unknown">
        <asp:button id="Button1" runat="server" text="Button" asp="#unknown" />
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900