EDN Admin
Well-known member
I know there other ways but i want to try ot use this way with indexof and substring.
What i did so far rivate void InsertContent()
{
StreamReader r = new StreamReader(localHtmlFile);
StreamWriter w = new StreamWriter(@"D:localscrambledfile.html");
string f = r.ReadToEnd();
int index;
string firstWord = "";
for (int i = 0; i < words.Count; i++)
{
firstWord = words;
int startTagWidth = firstWord.Length-1;
index = 0;
while (true)
{
index = f.IndexOf(firstWord, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
//index = f.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
string g = f.Substring(start, index);
w.WriteLine(g);
}
}
w.Close();
}
So lets say the first word is "com " and since there is a space before or after the word i did firstWord.Length-1
Now what i want to do is to find each time the next word(string) from the List words in the original file : localHtmlFile
Then i want to replace this words with the first word(index) in the List scrambledWords
Both Lists words and scrambledWords have the same number of index/strings
I want to find the first word in the original file then copt the content from the begining of the file untill the first word to the new file localscrambledfile.html after copied it to replace the word with the scrambledWords
And the to read the content from this point from the original file to the next word and so on...
To get ot the word copy the content untill this word then replace in the new file the word with the other word and so on untill the end.
How can i do it using this indexof and substring ?
View the full article
What i did so far rivate void InsertContent()
{
StreamReader r = new StreamReader(localHtmlFile);
StreamWriter w = new StreamWriter(@"D:localscrambledfile.html");
string f = r.ReadToEnd();
int index;
string firstWord = "";
for (int i = 0; i < words.Count; i++)
{
firstWord = words;
int startTagWidth = firstWord.Length-1;
index = 0;
while (true)
{
index = f.IndexOf(firstWord, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
//index = f.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
string g = f.Substring(start, index);
w.WriteLine(g);
}
}
w.Close();
}
So lets say the first word is "com " and since there is a space before or after the word i did firstWord.Length-1
Now what i want to do is to find each time the next word(string) from the List words in the original file : localHtmlFile
Then i want to replace this words with the first word(index) in the List scrambledWords
Both Lists words and scrambledWords have the same number of index/strings
I want to find the first word in the original file then copt the content from the begining of the file untill the first word to the new file localscrambledfile.html after copied it to replace the word with the scrambledWords
And the to read the content from this point from the original file to the next word and so on...
To get ot the word copy the content untill this word then replace in the new file the word with the other word and so on untill the end.
How can i do it using this indexof and substring ?
View the full article