string FILE_NAME = @"d:\vs2005\A.txt"; if (!File.Exists(FILE_NAME)) { Console.WriteLine("{0} does not exist.", FILE_NAME); return; } string[] str = File.ReadAllLines(FILE_NAME); int t = 0; bool bln = false; for (int x = 0; x < str.Length; x++) { if (str[x].StartsWith("/*")) bln = true; if (bln) t++; if (str[x].EndsWith("*/")) bln = false; } System.Console.WriteLine((t - 2).ToString()); }
a.txt內容為 /* A B C Ddfasdf sfas sfas sdf E F */ DDD S D D D
bool sign = false;
for(int i=0;i<strArray.Length;i++)
{
string str = strArray[i];
if(str.StartsWith("/*"))
sign = true;
if(sign)
lines++;
if(str.EndsWith("*/"))
break;
}
Regex reg=new Regex(@"/\*(.*?)/\*");
{
string FILE_NAME = @"d:\vs2005\A.txt";
if (!File.Exists(FILE_NAME))
{
Console.WriteLine("{0} does not exist.", FILE_NAME);
return;
}
string[] str = File.ReadAllLines(FILE_NAME); int t = 0;
bool bln = false;
for (int x = 0; x < str.Length; x++)
{
if (str[x].StartsWith("/*")) bln = true;
if (bln) t++;
if (str[x].EndsWith("*/")) bln = false;
}
System.Console.WriteLine((t - 2).ToString());
}
/*
A
B
C
Ddfasdf
sfas
sfas
sdf
E
F
*/
DDD
S
D
D
D