var file = File.ReadAllText(@"D:\localfile.html");
int idx = file.IndexOf("something");
int idx1 = file.IndexOf("</script>", idx);
string results = file.Substring(idx, idx1 - idx);
結果中的結果是:
arrayImageTimes.push('202110071730');arrayImageTimes.push('202110071745');arrayImageTimes.push('202110071800');arrayImageTimes.push('202110071815');arrayImageTimes.push('202110071830');arrayImageTimes.push('202110071845');arrayImageTimes.push('202110071900');arrayImageTimes.push('202110071915');arrayImageTimes.push('202110071930');arrayImageTimes.push('202110071945');
我需要提取 ' 和 ' 之間的每個數字并將每個數字添加到串列中
例如:提取數字 202110071730 并將此數字添加到串列中
uj5u.com熱心網友回復:
您可以先拆分;以獲取陳述句串列。
然后將每個陳述句拆分'為 . 之前,之間和之后的所有內容'。取中間的([1])。
string s = "arrayImageTimes.push('202110071730');arrayImageTimes.push('202110071745');arrayImageTimes.push('202110071800');arrayImageTimes.push('202110071815');arrayImageTimes.push('202110071830');arrayImageTimes.push('202110071845');arrayImageTimes.push('202110071900');arrayImageTimes.push('202110071915');arrayImageTimes.push('202110071930');arrayImageTimes.push('202110071945');";
var statements = s.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var statement in statements)
{
Console.WriteLine(statement.Split('\'')[1]); // add to a list instead
}
或者,對于所有 Regex 粉絲,使用一些數字'(\d )'捕獲一組':
Regex r= new Regex("'(\\d )'");
var matches = r.Matches(s);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value); // add to a list instead
}
正則運算式風暴
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/318263.html
