How to read two char at time in c#?

Posted by Allemahesh under C# on 7/19/2013 | Points: 10 | Views : 1797 | Status : [Member] [MVP] | Replies : 3
I have a string. Now I want to read 2 chars at a time in c#. For example:-

string str = "dotnetfunda";
Now I want to read do,tn,et,fu,nd,a like this
Can any one help me.




Responses

Posted by: Phagu007 on: 7/19/2013 [Member] Starter | Points: 25

Up
0
Down
You can use this code as guideline
char[] c = new char[10];
using (StreamReader streamReader = File.OpenText("c:\example.txt"))
{
streamReader.Read(c, 0, c.Length);
}

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 7/22/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
But I am not using any .txt file. How to do this with out .txt file

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nadeemshaik on: 7/22/2013 [Member] Starter | Points: 25

Up
0
Down
write code like this

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string str = "dotnetfunda";
string c1 = string.Empty;
for (int i = 0; i <= str.Length - 1; i++)
{
c1 = c1+str[i];
if (c1.Length == 2)
{
Console.WriteLine(c1);
Console.ReadLine();
c1 = string.Empty;
}
else if (c1.Length == 1)
{
if (i == str.Length - 1)
{
Console.WriteLine(c1);
Console.ReadLine();
}
}
}

}
}
}



Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response