递增字符串值 [英] Increment a string value
问题描述
如何增加字符串值?例如:
How can I increment a string value? For example:
string RECONCILIATION_COUNT;
if (thing happens) {
RECONCILIATION_COUNT++;
}
这通常是行不通的,因为不可能以与用于int值相同的方式来增加字符串变量.
This is normally wont work since it is not possible to increment a string variable in the same way used for int values.
RECONCILIATION_COUNT
始终是0到5之间的数字.
RECONCILIATION_COUNT
is always a number from 0-5.
我选择将其声明为字符串,因为我是从数据库中获取此值的,并且我没有找到如何从sql中获取int值的方法.
I chose to declare it as a string since I am getting this value from database and i am not finding a way how to get an int value from sql.
RECONCILIATION_COUNT = Rows["RECONCILIATION_COUNT"].toString();
这是我目前正在使用的.
This is what I am using for the moment.
推荐答案
将 count 作为 String
: int
到目前为止,这是很自然的选择.从技术上讲,您可以将其设置为
It's quite weird to have a count as a String
: int
is by far much natural choice. Technically, you can put it as
if (thing happens)
RECONCILIATION_COUNT = (int.Parse(RECONCILIATION_COUNT) + 1).ToString();
一个更好的实现是使用 int
:
a better implementation is to use int
:
int RECONCILIATION_COUNT;
...
if (thing happens)
RECONCILIATION_COUNT++;
...
RECONCILIATION_COUNT = Convert.ToInt32(Rows["RECONCILIATION_COUNT"]);
这篇关于递增字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!