I m trying to search an Html file for a list of words or phrases and write the file back out with added html tags around those words/phrases. The rest of the file needs to remain as is. I don t know how to get around the situation where a phrase is broken across two lines. Can anyone help? I m new to this so please be explicit in your answer.
这里有一份投入文件:(超文本标记在另一行)
<p>
The thousand injuries of Fortunato I had borne as I best could, but
when he ventured upon insult, I vowed revenge. You, who so well know
the nature of my soul, will not suppose, however, that I gave utterance
to a threat. <i>At length</i> I would be avenged; this was a point definitely
这里是迄今为止的法典:
//get the table of words
DataTable table = LibraryAccess.GetWords(titleID);
using (StreamReader streamReader = File.OpenText(fileUploadPath))
{
inputString = streamReader.ReadToEnd();
streamReader.Close();
textCopy.Append(inputString);
}
if (inputString != null)
{
inputString = inputString.ToUpper();
foreach (DataRow r in table.Rows)
{
searchWord = (r["Word"].ToString()).ToUpper();
wordLength = searchWord.Length;
foundIndex = inputString.IndexOf(searchWord);
//if (foundIndex >= 0)
//{
//Use the Stringbuilder to modify the output file, e.g. add Bold tags
//around the word/expression
//}
foundIndex = -1;
}
}
else
{
Response.Write("input string is empty");
}
}
The Word I m searching for is "gave utterance to" In the source file, there is a CRLF after utterance, so the Indexof is not finding the Word. I could easily replace the CRLF with a blank, but I need to put them back in the file when I write out the modified version. I don t know how to preserve them.
任何关于如何有效地做到这一点的想法? 我想花大量时间。 我最初是在读取语时这样做的,出于记忆原因,我更喜欢这样做,但会遇到同样的问题。 增 编