Home > Code > String Operations > Read line by line from string using C#

Read line by line from string using C#

by Thamil   on Oct 07, 2013   Category: String Operations   |  Views: 4414    |  Points: 25   |  Gold 

Sometime we may need to read the string line by line and store into string array for further processing, see the below two sample method how to read string value from given string,

string strVal = "Reading line\r\nby line in a \r\nstring using C#";
using (StringReader strRead = new StringReader(strVal))
string strGetLineVal;
while ((strGetLineVal = strRead.ReadLine()) != null)

string[] strArr = strVal.Replace("\r", "").Split('\n');
for (int i = 0; i < strArr.Count(); i++)
Response.Write(strArr.ToString() + "</BR>");

Post Code  |  Code Snippet Home

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts