Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have several string which I got from a file read.
Now I have to show them in a single text box which have multi-line properties
below I had given code

string FstArray = splite[0];
                    string SndArray = splite[1];
                    textBox2.Text = FstArray;


only third,fourth and seventh string should come one by one (not same line) in a particular text box

Thanks To All
Indrajit
Posted
Updated 6-Jul-11 23:32pm
v4

Assuming that splite is a String array, this single line should work fine.
textBox2.Text = String.Join(System.Environment.NewLine, splite)
 
Share this answer
 
Comments
Toniyo Jackson 7-Jul-11 5:04am    
Perfect. My 5
Prerak Patel 7-Jul-11 5:09am    
Thanks TJ* ;)
Sergey Alexandrovich Kryukov 7-Jul-11 5:07am    
Agree, my 5. This is much better then my solution.
--SA
Prerak Patel 7-Jul-11 5:09am    
Thank you SA.
IndrajitDasgupat 7-Jul-11 5:26am    
It shows all line But I need only third,fourth and seventh line how can I do that please help
Use System.Text.StringBuilder and concatenate the strings using System.Environment.NewLine as a separator.

Do not use "\n", "\r" or "\r\n" for a line separator — this is not portable!

C#
void PopulateTextBox(string[] source, TextBox destination) {
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    int count = 0;
    foreach(string line in source) {
        sb.Append(line);
        if (count < source.Length - 1)
             sb.Append(System.Environment.NewLine);
        ++count;
    }
    destination.Text = sb.ToString(); 
}


—SA
 
Share this answer
 
Comments
Toniyo Jackson 7-Jul-11 5:22am    
Good call. My 5
Sergey Alexandrovich Kryukov 7-Jul-11 5:24am    
Thank you, Toniyo.
--SA
Try this.
textBox2.Text = FstArray +  Environment.NewLine + FstArray;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Jul-11 5:09am    
Couple of problems here: repeated "+" is not effective because string is immutable; the intention is to use the array as data input.

My solution is correct, the one by Prerak is just perfect.
Toniyo Jackson 7-Jul-11 5:12am    
Yeah. After posting my answer i saw prerak and your answers. Its better than my answer :)
Sergey Alexandrovich Kryukov 11-Jul-11 0:51am    
Thank you, Toniyo.
--SA
Hello I think u should write code like below


C#
string str = "Hello, Hi, Hoo";
           string[]  strar = str.Split(',');
           foreach(string ss in strar)
           {
               TextBox1.Text = TextBox1.Text+ss + Environment.NewLine;

           }




Regards
Dwarika
 
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