我为数据库获取extLogonName
字符串,并依赖于我需要更改逻辑的最后一个字符(数字或字母)。
我使用长度-1来获取最后一个字符
char last = extLogonName[extLogonName.Length-1];
extLogonName是“moni.yewriwe2”,但不知何故最后还是给我50'2',我只期待2.但是现在确定50来了?
之后我尝试转换char last = System.Convert.ToChar(last1);
它仍然显示我50'2'。实际上我想创建登录名,如果相同的登录名后面添加数字请找到我的完整逻辑。
if (reader.HasRows)
{
while (reader.Read())
{
extLogonName = (string)reader["logonname"];
}
}
// char last = extLogonName[extLogonName.Length-1];
// String NewString = Substring(oldString.Length - 1, 1);
//String last = Substring(extLogonName.Length - 1, 1);
string last1= extLogonName.Substring(extLogonName.Length-1,1);
char last = System.Convert.ToChar(last1);
if ((last >= 'a' && last <= 'z'))
{
int i = 2;
logonname = extLogonName + i.ToString();
}
if (last >= '2' && last <= '9')
{
// char last2 = extLogonName[extLogonName.Length - 2];
string last3 = extLogonName.Substring(extLogonName.Length - 2, 1);
char last2 = System.Convert.ToChar(last3);
if (last2 >= '0' && last2 <= '9')
{
int number2 = (int)last2;
number2 = number2 + 1;
logonname = logonname + number2.ToString();
}
int number = (int)last;
//Char number =System.Convert.ToInt32(last);
number = number + 1;
logonname = logonname + number.ToString();
}
所以它创建'moni.yewriwe2'然后'moni.yewriwe51'并且我想要'moni.yewriwe3'。
答案 0 :(得分:0)
在ASCII表中,十进制50(十六进制32)表示字符&#39; 2&#39;。