quest_capital
asked on
How do I split up my string into substrings based on key charactors.
How do I break up my string into substrings... Lets say using "<!---->"
Start:
string myString = "<DIV class=ftrimage><A href=pic.asp><IMG src=168.jpg width=104></A></DIV><!---- >Bush
vows steps to bolster al-Maliki's ability to curb sectarian bloodshed.<!----><A href=pic.asp><IMG src=168.jpg width=104></A>";
Results:
myString1 = "<DIV class=ftrimage><A href=pic.asp><IMG src=168.jpg width=104></A></DIV>";
myString2 = "Bush vows steps to bolster al-Maliki's ability to curb sectarian bloodshed.";
myString3 = "<A href=pic.asp><IMG src=168.jpg width=104></A>";
Start:
string myString = "<DIV class=ftrimage><A href=pic.asp><IMG src=168.jpg width=104></A></DIV><!----
vows steps to bolster al-Maliki's ability to curb sectarian bloodshed.<!----><A href=pic.asp><IMG src=168.jpg width=104></A>";
Results:
myString1 = "<DIV class=ftrimage><A href=pic.asp><IMG src=168.jpg width=104></A></DIV>";
myString2 = "Bush vows steps to bolster al-Maliki's ability to curb sectarian bloodshed.";
myString3 = "<A href=pic.asp><IMG src=168.jpg width=104></A>";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a solution using regular expression.
using System.Text.RegularExpress
string myString = @"<DIV class=ftrimage><A href=pic.asp><IMG src=168.jpg width=104></A></DIV><!----
vows steps to bolster al-Maliki's ability to curb sectarian bloodshed.<!----><A href=pic.asp><IMG src=168.jpg width=104></A>";
MatchCollection mc = Regex.Matches(myString, "(?:(.*?)(?:<!---->|$))",
RegexOptions.Singleline);
string[] output = new string[mc.Count];
int idx = 0;
foreach( Match m in mc )
{
output[idx] = m.Groups[1].Value;
idx++;
}
// Print the array out
foreach (string line in output)
{
if( line != "" ) Console.WriteLine(line + "\n");
}
Fernando