WikiCrawler/MediaWiki/WikiUtils.cs
/// <summary>
/// Removes the first occurence of the specified template from the text.
/// </summary>
/// <returns>The new text.</returns>
Removes the first occurence of the specified template from the text.
Removes the first occurence of the specified template from the text .
public static string RemoveTemplate(string templateName, string text, out string template)
		{
			string startMarker = "{{" + templateName;
			int templateStart = text.IndexOf(startMarker);
			if (templateStart >= 0)
			{
				int templateEnd = text.IndexOf("}}", templateStart) + 2;
				if (templateEnd < text.Length && text[templateEnd] == '\n')
				{
					templateEnd++;
				}
				template = text.Substring(templateStart, templateEnd - templateStart);
				return text.Substring(0, templateStart) + text.Substring(templateEnd, text.Length - templateEnd);
			}
			else
			{
				template = "";
				return text;
			}
		}
public static string RemoveTemplate ( string templateName , string text , out string template ) { string startMarker = " " + templateName ; int templateStart = text . IndexOf ( startMarker ) ; if ( templateStart >= 0 ) { int templateEnd = text . IndexOf ( " " , templateStart ) + 2 ; if ( templateEnd < text . Length && text [ templateEnd ] == ' \n ' ) { templateEnd ++ ; } template = text . Substring ( templateStart , templateEnd - templateStart ) ; return text . Substring ( 0 , templateStart ) + text . Substring ( templateEnd , text . Length - templateEnd ) ; } else { template = " " ; return text ; } }
Removes the first occurence of the specified template from the text.
Removes the first occurence of the specified template from the text .
//TOOD: support nested templates // if the next character is a line return, get that too
The new text.
The new text .
templateName
string
text
string
string
out