的格局C#最后一次出现后,提取的所有字符 [英] Extract All Characters after last occurrence of a pattern C#

查看:288
本文介绍了的格局C#最后一次出现后,提取的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字符串是以下模式的

1.0.0.0
1.0.0.1
1.0.0.2
...
...
...

我在找这将读取的最后一个创建的字符串,并加1的最后一个数字,并将其保存为一个新的字符串代码。

I am looking for a code which will read the last created string and increment the last numeral by 1 and save it as a new string.

我该怎么办呢?

最好的问候,

魔术

推荐答案

您可以将字符串分割成组件,分析最后一个,这样就可以增加它,并再次一起把他们:

You can split the string into the components, parse the last one so that you can increase it, and put them together again:

string[] parts = version.Split('.');
parts[3] = (Int32.Parse(parts[3]) + 1).ToString();
version = String.Join(".", parts);

这可能会稍微更高效的另一种方法是使用字符串操作只得到了最后一个组件:

Another method that may be slightly more efficient is to get only the last component using string operations:

int pos = version.LastIndexOf('.') + 1;
int num = Int32.Parse(version.Substring(pos));
version = version.Substring(0, pos) + num.ToString();

这篇关于的格局C#最后一次出现后,提取的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆