有没有老大会将一个字符串如“abc”的每个字母的ASCII码都加一,变成“bcd”?
还要考虑如何处理字符串中空格的问题(空格不能改变)?

解决方案 »

  1.   

    Convert.ToInt32("a")这是把字母值转为ASCII码
    char c=(char)65; 这是把数字转为字符对应的ascii码。
    空格的ASCII码是32,你做个循环,或数组搞定一下,空格判断一下就行了。
      

  2.   

    string s = "A b C Z hhhasd asd";
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    foreach(char ch in s)
    {
    sb.Append((ch != 32) ? Convert.ToChar(ch + 1) : ch);
    }
    结果为
    B c D [ iiibte bte
      

  3.   

    可以改进一下
    string s = "A b C Z hhhasd asd";
    System.Text.StringBuilder sb = new System.Text.StringBuilder(s.Length);//这样性能会提高一些,因为这样可以避免多次分配内存
    foreach(char ch in s)
    {
    sb.Append((ch != 32) ? (char)(ch + 1) : ch);
    }
      

  4.   

    byte[] xy = System.Text.Encoding.ASCII.GetBytes("A");
    string kk = xy[0].ToString();用这个把A字符转换。呵呵。
      

  5.   

    可以改进一下
    string s = "A b C Z hhhasd asd";
    System.Text.StringBuilder sb = new System.Text.StringBuilder(s.Length);//这样性能会提高一些,因为这样可以避免多次分配内存
    foreach(char ch in s)
    {
    sb.Append((ch != 32) ? (char)(ch + 1) : ch);
    }这个就挺好的
      

  6.   

    string s = "A b C Z hhhasd asd";
    int i;
    for(i = 0 ; i < s.GetLength(0); ++i)
    {
      s[i] = s[i] == ' ' ? s[i] : (char)(s[i] + 1);
    }
      

  7.   

    string s = "A b C Z"; System.Text.StringBuilder sb = new System.Text.StringBuilder(s.Length);//这样性能会提高一些,因为这样可以避免多次分配内存
    foreach(char ch in s)
    {
    if(ch != 32 )
    {
    sb.Append((char)(ch + 1));
    }
    else
    {
    sb.Append(ch);
    }
    }