ASP.net中字符串到字符的转换

ASP.net中字符串到字符的转换,asp.net,string,Asp.net,String,我正在获取数据库的extLogonName字符串,根据需要更改逻辑的最后一个字符(数字或字母表)。 我使用length-1获取最后一个字符 char last = extLogonName[extLogonName.Length-1]; extLogonName是“moni.yewriwe2”,但不知怎么的,last返回了50'2,我只期望2。但现在确定50是从哪里来的 之后,我尝试转换charlast=System.convert.ToChar(last1) 它仍然显示我50'2'。实际上我

我正在获取数据库的
extLogonName
字符串,根据需要更改逻辑的最后一个字符(数字或字母表)。 我使用length-1获取最后一个字符

char last = extLogonName[extLogonName.Length-1];
extLogonName是“moni.yewriwe2”,但不知怎么的,last返回了50'2,我只期望2。但现在确定50是从哪里来的

之后,我尝试转换
charlast=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();
              }  
if(reader.HasRows)
{
while(reader.Read())
{
extLogonName=(字符串)读取器[“logonname”];
}
}
//char last=extLogonName[extLogonName.Length-1];
//String NewString=子字符串(oldString.Length-1,1);
//字符串last=Substring(extLogonName.Length-1,1);
string last1=extLogonName.Substring(extLogonName.Length-1,1);
char last=System.Convert.ToChar(last1);

如果((last>='a'&&last='2'&&last='0'&&last2在ASCII表中,十进制50(十六进制32)表示字符“2”。

谢谢您的帮助。调试可能会很痛苦。很乐意帮忙。引用ASCII可能会引起混淆。“2”是UTF-16代码单元(
char
).UTF-16是Unicode字符集的几种编码之一。UTF-16以一个或两个代码单位对一个代码点进行编码。对于“2”,只需要一个。
'2'==50
。有关代码点列表和UTF-16的工作原理,请参阅。感谢大家的提醒,@TomBlodget。