gpt4 book ai didi

c# - 如何根据字母和数字在 C# 中拆分字符串

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

如何在 C# 中将“Mar10”等字符串拆分为“Mar”和“10”?字符串的格式始终是字母然后是数字,因此我可以使用数字的第一个实例作为字符串拆分位置的指示符。

最佳答案

你可以这样做:

var match = Regex.Match(yourString, "(\w+)(\d+)");
var month = match.Groups[0].Value;
var day = int.Parse(match.Groups[1].Value);

关于c# - 如何根据字母和数字在 C# 中拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2362153/

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