hello friends
I am new to c# and i want to know how to read contents from a file and store in an array not word by word but depending on the no of characters including space
example:
string:Hi how are you?
packet size:4
then i shall get: a[0]=hi h
a[1]=ow a
a[2]=re y
a[3]=ou?
please help
thanks

Amit Kumar SinghRank #562 · 4.3K reputationPosted Mar 3, 2016, 4:01 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 3, 2016, 4:13 PM EST
Easier to store it in a list, array is not resizable..If you want you can modify it to store in an array..
int packetSize = 4; lst = new List();
string test = File.ReadAllText(@"Path");
List
while (test.Length > packetSize)
{
lst.Add(test.Substring(0, packetSize));
}
if (test != string.Empty)
{
lst.Add(test);
}
theLizardRank #1,079 · 1.8K reputationPosted Mar 3, 2016, 4:56 PM EST
string[] words = new string[0];
int packetSize = 4;
while(s.Length > 0)
{
Array.Resize(ref words, words.Length + 1);
if (s.Length > packetSize)
words[words.Length - 1] = s.Substring(0, packetSize);
else
{
words[words.Length - 1] = s;
s = "";
}
if (s.Length > packetSize)
s = s.Substring(packetSize);