Elchi
13-02-2012, 20:30
Ich habe mich mehrere Stunden an dem hier abgebissen, nachdem ich es geschrieben habe, aber ich weiß immer noch nicht, wo der Fehler liegt (HILFE!!!!)
#UseInterface Web;
Var idx As Integer = 0;
Function parse(t As String) As CHtmlControl
{
Var text As String = t;
Var index As Integer = 0;
Var form As New CHtmlControl();
Var i As Integer = text.IndexOf("[");
Var o As Integer;
While(i >= 0)
{
form.Add(text.Substring(0, i));
o = text.IndexOf("]");
If(o <= (i - 1))
{
form.Add("!!!");
Return form;
}
Var tagname As String = text.Substring(i + 1, (o - i) - 1);
index = index + o + 1;
If(tagname.Substring(0, 1) = "/")
{
idx = index + idx;
Return form;
}
Var current As New CHtmlControl();
If(tagname = "b")
{
current = New CHtmlBig();
}
If(tagname = "red")
{
current = New CHtmlSpan();
current.Style.Add("color", "#ff0000");
}
current.Add(parse(text.Substring(index)));
form.Add(current);
text = text.Substring(index + idx - 1);
index = 0;
i = text.IndexOf("[");
}
form.Add(text);
idx = text.Length - 1;
Return form;
}
Var form As New CHtmlForm(New CScriptUrl());
form.Add(parse("[b][red]ROT[/][/]"));
Response.Add(form);
#UseInterface Web;
Var idx As Integer = 0;
Function parse(t As String) As CHtmlControl
{
Var text As String = t;
Var index As Integer = 0;
Var form As New CHtmlControl();
Var i As Integer = text.IndexOf("[");
Var o As Integer;
While(i >= 0)
{
form.Add(text.Substring(0, i));
o = text.IndexOf("]");
If(o <= (i - 1))
{
form.Add("!!!");
Return form;
}
Var tagname As String = text.Substring(i + 1, (o - i) - 1);
index = index + o + 1;
If(tagname.Substring(0, 1) = "/")
{
idx = index + idx;
Return form;
}
Var current As New CHtmlControl();
If(tagname = "b")
{
current = New CHtmlBig();
}
If(tagname = "red")
{
current = New CHtmlSpan();
current.Style.Add("color", "#ff0000");
}
current.Add(parse(text.Substring(index)));
form.Add(current);
text = text.Substring(index + idx - 1);
index = 0;
i = text.IndexOf("[");
}
form.Add(text);
idx = text.Length - 1;
Return form;
}
Var form As New CHtmlForm(New CScriptUrl());
form.Add(parse("[b][red]ROT[/][/]"));
Response.Add(form);