When writing a questionnaire, you may encounter a small problem of splitting strings. The webpage name is "Browse _" + survey number + "_" webpage code. html there are many ways to get the survey number and page number. For example, you can use string Split. Use regular expressions for analysis: the data is actually between two underlines and periods. Therefore, write a regular expression: _ \ d {1, }_\ d {1 }\. _ \ d {1, }_\ d {1 }\. meaning: _: Match underline \ d {1,}: Match one or more numbers \.: Indicates matching a dot. Because the DOT has a special meaning, the escape character slash is used. The overall meaning is to first match an underline, then match one or more numbers, then match the underline, then match one or more numbers, finally match a point number, and finally name the matched data, name \ d {1,} matched in the first position as surveyID, and \ d {1,} matched in the second place as pageIndex. Then, the regular expression is changed _(? <SurveyID> \ d {1 ,})_(? <PageIndex> \ d {1}) \. Test code:
public static bool GetPageIndexSurveyID(string url, ref int surveyID, ref int pageIndex) { Regex reg = new Regex(@"_(?<surveyID>\d{1,})_(?<pageIndex>\d{1})\."); if (reg.IsMatch(url)) { Match m = reg.Match(url); surveyID = int.Parse(m.Groups["surveyID"].Value); pageIndex = int.Parse(m.Groups["pageIndex"].Value); } return true; }