i like to read check the text has multi line or single line and then i am going to read that multi lines and convert into single line how can i do this?
            Asked
            
        
        
            Active
            
        
            Viewed 7,561 times
        
    4 Answers
7
            You really do not need to check as File.ReadAllLines() will always return a string array regardless of the number of lines. You can leverage that behavior and simply join the returned array with your separator of choice.
string singleLine = string.Join(" ", File.ReadAllLines("filepath"));
 
    
    
        Sky Sanders
        
- 36,396
- 8
- 69
- 90
0
            
            
        string text = String.Empty;
if(textbox.Text.Contains(Environment.NewLine))
{
    //textbox contains a new line, replace new lines with spaces
    text = textbox.Text.Replace(Environment.NewLine, " ");
}
else
{
    //single line - simply assign to variable
    text = textbox.Text;
}
 
    
    
        David Neale
        
- 16,498
- 6
- 59
- 85
0
            
            
        try something like that (depends on how you treat "lines"):
System.IO.File.ReadAllText(path).Replace("\n\r", "");
 
    
    
        UserControl
        
- 14,766
- 20
- 100
- 187
- 
                    1The correct CRLF would be `"\r\n"`. But much better would be `Environment.NewLine` – Oliver May 18 '10 at 08:13
0
            
            
        This will read all the lines from a text file and join them into one string with ; as a separator:
string[] lines = File.ReadAllLines("myfile.txt");
string myLine = String.Join(";", lines);
 
    
    
        Andre
        
- 1,107
- 11
- 22
