When I do a Reader.ReadToEnd() it returns \n\r , How do I convert that String into array without '\n\r' , Even better, how do I give a signal that \n\r is a new index in the array?
            Asked
            
        
        
            Active
            
        
            Viewed 135 times
        
    0
            
            
        - 
                    Use ``Split`` function based on ``\n\r`` – sa-es-ir May 08 '22 at 11:15
- 
                    1Windows line endings are usually `\r\n`, not `\n\r` – knittl May 08 '22 at 11:24
- 
                    Have you checked https://stackoverflow.com/questions/1547476/easiest-way-to-split-a-string-on-newlines-in-net? – user107511 May 08 '22 at 11:44
- 
                    2Just use `ReadLines()` method – Alexander Petrov May 08 '22 at 12:32
2 Answers
1
            
            
        You can use the following:
var array = Reader.ReadToEnd().Split("\r\n", StringSplitOptions.None);
This will remove all the new-line characters from the array and leave what is in between them as seperate elements.
The StringSplitOptions has enum values that determine whether empty (StringSplitOptions.RemoveEmptyEntries) or white-space (StringSplitOptions.TrimEntries) substrings should be omitted.
 
    
    
        Huntbook
        
- 114
- 9
0
            
            
        If your input lines are coming from the OS you run at, you can:
string[] lines = Reader.ReadToEnd().Split(Environment.NewLine, StringSplitOptions.None);
This way you don't care about the environment of you code.
 
    
    
        user107511
        
- 772
- 3
- 23
