我想从 MSBuild 中的字符串中提取数字。
我如何使用内置任务或 MSBuild.Community.Tasks 做到这一点? (RegexMatch 可能会这样做,但怎么做?)
示例:我有字符串
agent0076
我想取出数字,不带前导零:
76
最佳答案
使用 MSBuild 4 属性函数
<Target Name="Regex">
<PropertyGroup>
<In>agent0076</In>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), `[1-9]\d*`))</Out>
</PropertyGroup>
<Message Text="Input : $(In) Output : $(Out)"/>
<!-- Input : agent0076 Output : 76 -->
</Target>
关于regex - 从 MSBuild 中的字符串中提取数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2982559/