I want to parse this string: "2.8\r\n2.52\r\n" to just get 2.8 and 2.52. How can I go about doing something like this? I tried to using .Split() but I'm not sure what to pass as parameters to get what I am looking for.
            Asked
            
        
        
            Active
            
        
            Viewed 61 times
        
    0
            
            
         
    
    
        salpenza
        
- 37
- 7
- 
                    Use a Regular Expression. – Dai Jun 18 '20 at 20:40
- 
                    1There are a lot of duplicates of this question [split strings into many strings by newline?](https://stackoverflow.com/questions/21514387/split-strings-into-many-strings-by-newline) – Pavel Anikhouski Jun 18 '20 at 20:54
- 
                    @PavelAnikhouski cool – salpenza Jun 18 '20 at 20:59
2 Answers
4
            String.Split should work fine:
string[] res = "2.8\r\n2.52\r\n".Split("\r\n", StringSplitOptions.RemoveEmptyEntries); // array with {"2.8", "2.52"}
 
    
    
        Guru Stron
        
- 102,774
- 10
- 95
- 132
2
            
            
        You need to split by Environment.NewLine which in here would be \r\n
var result = "2.8\r\n2.52\r\n".Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
Edit:
Environment.NewLine depends on your environment as you can guess so to be on the safe side you can also use the exact string (\r\n) as a delimiter.
 
    
    
        Arin Ghazarian
        
- 5,105
- 3
- 23
- 21