المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : getting specific string error?



C# Programming
07-14-2009, 12:51 AM
i want to fetch the characters from file for example :

1st example:

// mehmood// hello ,how r u?

just within comments and replace it to all caps

2nd example:

/* hi
mehmood
ahmed */


i want to fetch the characters within sigle line comment and multi line comments .

just within comments not outside the comment.

--------------------------------------------------------------------------------

i am trying this code, kindly correct my code:

FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);

StreamReader sr = new StreamReader(fs);
int countComment=0;
while(sr.Peek() >= 0 )
{
str =sr.ReadLine();
strTemp = new char[str.Length];
#region From String method
int count=0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == '/')
{
++countComment;
count=i;
}
if (char.IsLetterOrDigit(str,count+1) && countComment==2)
{
strTemp2 += str.Substring(count+1).ToUpper();
}

}
#endregion


countComment = 0;
this.textBox2.Text += strTemp2 + Environment.NewLine; ;
this.textBox1.Text += str + Environment.NewLine;
}
sr.Close();
fs.Close();



it generates an exception :

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index

Maifs