如何编写此文本然后将其递增1? C# [英] How can i write this text and then increment it by 1? c#

查看:52
本文介绍了如何编写此文本然后将其递增1? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您愿意为我编写此代码,我会非常感谢它!在我的宏中,我将只使用一个按钮激活此代码,因此每次运行时都必须编写路径,这可能是
Documents / test_1.cs 然后下次激活代码再次是
Documents / test_2.cs

If you would kindly write this code for me i will really appreciate it like a lot !!! In my macro i will just use a button to activate this code so each time it runs it will have to write the path which could be something Documents/test_1.cs then next time i activate the code again it would be Documents/test_2.cs

只要观看视频,你就会明白我想要做什么;)

Just watch the video and you will understand what i am trying to do ;)

https://youtu.be/xYuidYmCWS8

https://youtu.be/xYuidYmCWS8

推荐答案

Hello TheUninvited123,

Hello TheUninvited123,

1。请尝试以下操作:

1. Try the following for a start :

string IncrementFileName(string strLastFileName)
{
    string strBasicFileName = "test__";
    int iLastCount = Convert.ToInt32(strLastFileName.Substring(strBasicFileName.Length));
    return string.Format("{0:S}{1:D}", strBasicFileName, ++iLastCount);
}

2。您可以按如下方式调用上述函数:

2. You can call the above function as follows :

string strNewFileName = IncrementFileName("test__5");

3。希望这会有所帮助。

3. Hope this helps.

- 生物。


这篇关于如何编写此文本然后将其递增1? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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