gpt4 book ai didi

c# - 如何在 C# 中使用 Regex 检索选定的文本?

转载 作者:可可西里 更新时间:2023-11-01 08:08:11 25 4
gpt4 key购买 nike

如何在 C# 中使用 Regex 检索选定的文本?

我正在寻找与此 Perl 代码等效的 C# 代码:

$indexVal = 0;
if($string =~ /Index: (\d*)/){$indexVal = $1;}

最佳答案

int indexVal = 0;
Regex re = new Regex(@"Index: (\d*)")
Match m = re.Match(s)

if(m.Success)
indexVal = int.TryParse(m.Groups[1].toString());

我可能组号不对,但你应该能从这里算出来。

关于c# - 如何在 C# 中使用 Regex 检索选定的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com