既不快,也不高效,但它更容易理解,爲這些新的正則表達式:
while (!endOfFile)
{
//get the next line of the file
string line = file.readLine();
EDIT: //Trim WhiteSpaces at start
line = line.Trim();
//check for your string
if (line.StartsWith("addTestingPageContentText"))
{
int start1;
int start2;
//get the first something by finding a "
for (start1 = 0; start1 < line.Length; start1++)
{
if (line.Substring(start1, 1) == '"'.ToString())
{
start1++;
break;
}
}
//get the end of the first something
for (start2 = start1; start2 < line.Length; start2++)
{
if (line.Substring(start2, 1) == '"'.ToString())
{
start2--;
break;
}
}
string sometext1 = line.Substring(start1, start2 - start1);
//get the second something by finding a "
for (start1 = start2 + 2; start1 < line.Length; start1++)
{
if (line.Substring(start1, 1) == '"'.ToString())
{
start1++;
break;
}
}
//get the end of the second something
for (start2 = start1; start2 < line.Length; start2++)
{
if (line.Substring(start2, 1) == '"'.ToString())
{
start2--;
break;
}
}
string sometext2 = line.Substring(start1, start2 - start1);
}
}
但是我會認真去推薦通過互聯網上的一些偉大的教程。 This是相當不錯的一個
小心行開頭的空白。這會拋棄你的'line.StartsWith(「addTestingPageContentText」)'條件。 –
你也可以用'string.IndexOf'替換'for'循環。 –
良好的調用,我認爲空白有一個錯誤從轉換到代碼在帖子中,而不是在數據中。在這種情況下,用string.Trim()修剪空白將是一個很好的起點。 –