This is definitely easiest to do with some regular expressions. Play around with the following code:
---
using System;
using System.Collections.Generic
using System.Text;
using System.Text.RegularExpress
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
string input =
@"This is some text
<!--
This is an sgml comment
-->
This is some other text
<!--
This is another sgml comment
-->";
string result =
Regex.Replace(
input,
@"<!--(.+?)-->",
EvaluateMatch,
RegexOptions.Singleline
);
Console.WriteLine(result);
Console.ReadLine();
}
private static string EvaluateMatch(Match m) {
return
"[[Replaced '" + m.Value.Trim() +
"' at position " + m.Index + "]]";
}
}
}
Main Topics
Browse All Topics





by: FernandoSotoPosted on 2006-10-29 at 10:42:23ID: 17829600
Hi clickclickbang;
ions;
This will parse your string.
using System.Text.RegularExpress
string input = "Your string to parse";
ArrayList al = new ArrayList();
MatchCollection mc = Regex.Matches(input, @"<!---\r\n(.*?)\r\n-->");
foreach( Match m in mc )
{
al.Add(m.Groups[1].Value);
}
There will be 3 elements in the array list with these values.
The First Comment
The Second Comment
The Third Comment
Fernando