for a recent project I came up with this function
look beneath it for information on how it work
private string ExtractInformation(string Post)
{
List<string> Objects = new List<string>();
List<string> EndResult = new List<string>();
for (int A = 0; A < Post.Length - 1; ++A)
{
if (Post.Substring(A, 1) == "[" & Post.Substring(A,2)!="[/")
{
for (int B = A; B < Post.Length - 1; ++B)
{
if (Post.Substring(B, 1) == "]")
{
string Item = Post.Substring(A + 1, B - (A + 1));
if (!Objects.Contains(Item) & Item.Length > 1) { Objects.Add(Item); }
break;
}
}
}
}
for (int A = 0; A < Objects.Count; ++A)
{
string StartString = "[" + Objects[A] + "]";
string EndString = "[/" + Objects[A] + "]";
string AltEnd = "[/]";
for (int B = 0; B < Post.Length - StartString.Length; ++B)
{
if (Post.Substring(B, StartString.Length) == StartString)
{
int C = B;
while (C < Post.Length)
{
if (C < Post.Length - EndString.Length)
{
if (Post.Substring(C, EndString.Length) == EndString)
{
EndResult.Add(Objects[A] + "=" +Post.Substring(B + StartString.Length , C - (B + StartString.Length)));
break;
}
}
if (C < Post.Length - AltEnd.Length)
{
if (Post.Substring(C, AltEnd.Length) == AltEnd)
{
EndResult.Add(Objects[A] + "=" + Post.Substring(B + StartString.Length, C - (B + StartString.Length)));
break;
}
}
++C;
}
}
}
}
StringBuilder NewPost = new StringBuilder();
for (int A = 0; A < EndResult.Count; ++A)
{
NewPost.AppendLine(EndResult[A]);
}
return NewPost.ToString();
}this functions retrieve all of the information that is 'labeled'.
lets say we have a piece of text that is label using words that are located between
'[' & ']'
[Username]Huntondoom[/Username] [Derp]Hello everyone this is some shit[/] how do you do? [Lolz] this works! [/Lolz]
this function will then look for all the Headers that are used (as in getting the words between '[' & ']')
but if the text in between is 1 character big it will be skipped and found unworthy
all of these 'Headers' will be stored in a list so it would look like this
Username
Derp
Lolz
then It will retrieve the information that is located between a headers and its counterpart (usually its the header with a '/' infront of it)
but it also response against a universal counterpart = '[/]'
so you dont need to put in stuff like '[/Username]' but just '[/]'
this all will be stored inside of a list, along side its header that said it should be Extracted.
so:
Username=Huntondoom
Derp=Hello everyone this is some shit
Lolz=this works!
and that will be converted to a string and returned