比如把一个字符串中的每一个字符都变成他后面三个的字符。比如‘A’变成‘D’,‘H’变成‘K’~~在C#里是用Uuicode字符,不能直接象C中一样直接加一个整形数字的,是吧。我是一个新手,希望高人指教啊。

解决方案 »

  1.   

    int x = ((int)'A')+3;
    MessageBox.Show(Convert.ToString((char)x));
      

  2.   

    有两种方法
    1.把给定字母转换出它的assic码然后加3,然后再转回来。
    2.写一个方法,不过基本上写死的,如
    public string ConvertToAssic(string str)
    {
        switch (str)
        {
            case "A":
               str="D";
               break;
            case "B":
               str="E";
               break;
            //.........
        }
        return str;
    }
      

  3.   

    string x = (((int)'A')+3).ToString;
      

  4.   


    这是我按 cnhgj(戏子) (谁能告诉我Jeode怎么支持中文?)的方法写的,有什么问题么?using System;
    using System.Windows.Forms;namespace ConsoleApplication2
    {
    class Welcome
    {
    static void Main()
    {
    Console.WriteLine("Please enter your String:");
    string str = Console.ReadLine();
    char[] st = new char[str.Length];

    for( int i=0; i < str.Length-1; i++)
    {
    int x = 0; if( i == 0 )
    st[i] = str[str.Length-1]; x = ((int)str[i]) + 3;
    st[i+1] = MessageBox.Show( Convert.ToString( (char)x ) );
    } Console.Write("The result is:");
                
    for( int i=0; i < str.Length; i++)
    Console.Write("{0}", st[i]);

    Console.Write("\n");
    }
    }
    }这是错误报告。D:\Program Files\Microsoft Visual Studio .NET 2003\Visual Studio Projects\ConsoleApplication2\Class1.cs(22): 无法将类型“System.Windows.Forms.DialogResult”隐式转换为“char”
      

  5.   

    哦,我调试好了。谢谢各位。
    这是代码。嘿嘿。不好意思,我是新手,水平太低,见笑了。结帐啦~using System;
    using System.Windows.Forms;namespace ConsoleApplication2
    {
    class Welcome
    {
    static void Main()
    {
    Console.WriteLine("Please enter your String:");
    string str = Console.ReadLine();
    char[] st = new char[str.Length];

    for( int i=0; i < str.Length-1; i++)
    {
    int x = 0; if( i == 0 )
    st[i] = str[str.Length-1]; x = ((int)str[i]) + 3;
    st[i+1] = ( (char)x );
    } Console.Write("The result is:");
                
    for( int i=0; i < str.Length; i++)
    Console.Write("{0}", st[i]);

    Console.Write("\n");
    }
    }
    }