gpt4 book ai didi

c# - 检查字符串是否包含字符和数字

转载 作者:太空狗 更新时间:2023-10-29 23:58:17 25 4
gpt4 key购买 nike

如何检查字符串是否包含以下字符“-A”后跟数字?

例如:thisIsaString-A21 = yes,包含“-A”后跟一个数字

例如:thisIsaNotherString-AB21 = no,不包含后跟数字的“-A”

最佳答案

可以用正则表达式来完成:

if (Regex.IsMatch(s, @"-A\d")) { ... }

\d 匹配任何数字。

在线查看它:ideone

关于c# - 检查字符串是否包含字符和数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11197987/

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