What I'm trying to do is open a file and search for "searchText" I want to change with a new link, which is actually the filename with only aher link, so rather than opening javascript, it goes to the second point in the page.
So far what do I have:
Private Zero WriteNotes () {StreamReader Reader = New Stream Reader (OpenFileDialog1.Filename); String content = Reader Readout (); Reader.Close (); String filename = openFileDialog1.SafeFileName; String search text = "& lt; one class = \" x-fn \ "href = \" javascript: zero (0); \ "& Gt;"; String replaced = text = "& lt; one class = \" x-fn \ "href = \" + + + filename + "#fn" + "\" & gt; "; Content = Regex. Replace (content, search, text); Streamer Writer Writer = New Streamer (OpenFileDialog1.filename); writer.Write (content); writer.Close (); However, after writing and closing ... I open the file and no changes were made. Besides, what I want to do is add a number that for every instance of the replacement "#fn "Counts after, therefore, basically, every time I Javan I change the script link to another, then I want it:
& lt; a class = "x-fn" href = "fileName # fn1" & gt; And then when I replace the second example of javascript, then it
& lt; a class = "x-fn" href = "fileName # fn2 Reads "> and so on ...
I think javascript appears how many times the examples will be counted, to change it , And use a loop for all the new links to re-run and Adding #fn (n) to the end?
Your problem is that you have metaccharactors (this In the case, open and close traction in "zero (0)"). Rather than representing literally open and close legs, it is creating a regular expression group, which is causing your match to fail, if you avoid feet with backslash, then it will work as expected.
However, since you are matching only one string word, you do not need to use regular expressions; It will be faster to use string.Replace . For the second part of your question, this is a bit tricky, there is no easy way to do what I know, the best way is to look at your search text in the input, and then one While creating code, StringBuilder increases the counting variable in the following example, the word "the" has been changed for simplicity by "(0)" and "(1)", Can easily customize. var content = "Quick brown fox to jump on a celestial dog"; Var searchText = "the"; Var sb = new stringbilder (); Var idx = -1; // will retain the indicator of our search text IXx = 0; // Start Index of 0 that has not yet been copied the paradigm = 0; While everything (leading to idx = content.IndexOf (searchText, idx + 1))! = -1) {// our search text sb.Append (content.Substring (uncopiedIdx, idx-uncopiedIdx)); Replacement number var replacement = "(" + + replace + + + ")" copy replacement text "; Sb.Append (replacement); // search text unopodedxx = idx + searchText.Length; Skip on;} // Copy everything after the last match sb.Append (content.Substring (uncopiedIdx));
Comments
Post a Comment