What i'm doing
I have a string with html information like this:
<p> <span class="fieldText" fieldId="field-4">Some text</span> this is a test</p>
My goal in the method is to create a dictionary with this value:
**key** **value**
field-4 Some text
This is the code that i'm using to accomplish my task:
public static Dictionary<int,String> getFields(String mensaje)
{
Dictionary<int,String> fields = new Dictionary<int,string>();
Match m = Regex.Match(mensaje, @"^(.*?<span .*?>(.*?)</span>.*?)+$", RegexOptions.Singleline);
for (int i = 0; i < m.Groups[2].Captures.Count; i++)
{
String value = m.Groups[1].Captures[i].Value;
Match m2 = Regex.Match(value, "^(.*?fieldId=.*?\"(.*?)\">.*?)+$", RegexOptions.Singleline);
String fieldId = m2.Groups[2].Captures[0].Value;
fieldId = fieldId.Replace("field-", String.Empty);
fields.Add(int.Parse(fieldId),m.Groups[2].Captures[i].Value);
}
return fields;
}
How can i improve my code?