There is no special function for this action. After having loaded the text with Load() function you'll have to find a proper place for insertion yourself. You can use regular expressions or traditional .NET functions like IndexOf(). There is also a useful helper DotNetWikiBot function called Bot.GetMatchesPositions() - http://dotnetwikibot.sourceforge.net/help/html/M_DotNetWikiBot_Bot_GetMatchesPositions.htm . You can use it to find sections and subsections like this:
I thank CodeDriller for this hint and add the following code to the page class.
public List<int> SectionPositions {get; private set; }
public List<string> SectionContents {get; private set; }
public void ReadSections()
{
// get the positions where a new wiki section starts
SectionPositions = Bot.GetMatchesPositions(text, "\n=", false);
// if there is text before the first heading, insert a section 0
if(SectionPositions[0] > 0) {
SectionPositions.Insert(0, 0);
}
// divide all the text to each section;
// using Linq may be more easier, but I don't know how
SectionContents = new List<string>(SectionPositions.Count);
int i1;
for(int i = 0; i < SectionPositions.Count; i++) {
i1 = (i < SectionPositions.Count-1 ?
SectionPositions[i+1] - SectionPositions[i] :
text.Length - SectionPositions[i]);
SectionContents.Add(text.Substring(SectionPositions[i], i1));
}
}
A specific section text is called by SectionContents[sectionNo]. Juergen
By the way, I use "partial class Page" in order to simplify those additions by adding my own cs file.
Last edit: Juergen Thomas 2015-03-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For example, a page has 5 sections (section1...
Section5). I want to append some text to section4. How do I do this with dotnetwikibot?
Thanks in advance,
Sanketh
There is no special function for this action. After having loaded the text with Load() function you'll have to find a proper place for insertion yourself. You can use regular expressions or traditional .NET functions like IndexOf(). There is also a useful helper DotNetWikiBot function called Bot.GetMatchesPositions() - http://dotnetwikibot.sourceforge.net/help/html/M_DotNetWikiBot_Bot_GetMatchesPositions.htm . You can use it to find sections and subsections like this:
Last edit: CodeDriller 2013-12-05
I thank CodeDriller for this hint and add the following code to the page class.
A specific section text is called by SectionContents[sectionNo]. Juergen
By the way, I use "partial class Page" in order to simplify those additions by adding my own cs file.
Last edit: Juergen Thomas 2015-03-15