How to get values between two tags C#
private void df(string htmlTempate, out int widthPersonal, out int widthTimeLineLi)
{
widthPersonal = 0;
widthTimeLineLi = 0;
Regex regexPersonalInfo = new Regex("<widthpersonalstart>(.*)<widthpersonalend>");
Regex regexTimelineLi = new Regex("<widthtimelinestart>(.*)<widthtimelinend>");
var v = regexPersonalInfo.Match(htmlTempate);
if (v.Groups != null && v.Groups.Count > 0) {
string _widthPersonal = v.Groups[1].ToString().Trim();
int.TryParse(_widthPersonal, out widthPersonal);
}
var v2 = regexTimelineLi.Match(htmlTempate);
if (v2.Groups != null && v2.Groups.Count > 0) {
string _widthTimeLineLi = v2.Groups[1].ToString().Trim();
int.TryParse(_widthTimeLineLi, out widthTimeLineLi);
}
}
Where sample htmlTempate is as follows:
" dasf afadf af adfadf af <widthpersonalstart> 800 <widthpersonalend> afafadfa a adf af a adf af a adfa<widthtimelinestart>154<widthtimelinend> adfa f af adf adf ads";
Thanks
Mahesh
private void df(string htmlTempate, out int widthPersonal, out int widthTimeLineLi)
{
widthPersonal = 0;
widthTimeLineLi = 0;
Regex regexPersonalInfo = new Regex("<widthpersonalstart>(.*)<widthpersonalend>");
Regex regexTimelineLi = new Regex("<widthtimelinestart>(.*)<widthtimelinend>");
var v = regexPersonalInfo.Match(htmlTempate);
if (v.Groups != null && v.Groups.Count > 0) {
string _widthPersonal = v.Groups[1].ToString().Trim();
int.TryParse(_widthPersonal, out widthPersonal);
}
var v2 = regexTimelineLi.Match(htmlTempate);
if (v2.Groups != null && v2.Groups.Count > 0) {
string _widthTimeLineLi = v2.Groups[1].ToString().Trim();
int.TryParse(_widthTimeLineLi, out widthTimeLineLi);
}
}
Where sample htmlTempate is as follows:
" dasf afadf af adfadf af <widthpersonalstart> 800 <widthpersonalend> afafadfa a adf af a adf af a adfa<widthtimelinestart>154<widthtimelinend> adfa f af adf adf ads";
Thanks
Mahesh
No comments:
Post a Comment