C#问题,字符问题
来源:百度知道 编辑:UC知道 时间:2024/06/05 00:18:38
将字符串中每个字符的编码都增大n,再将字符串输出
using system;
class MyCode
{
static void Main()
{
string s="";
int n;
n=Int32.Parse(Console.ReadLine());
s=Console.ReadLine();
Method(s,n);
}
public static void Method(string s;int n)
{
int i,j;
for(i=0;i<length(s);i++)
{
j=Int32(s)+n;
j=char(j);
}
return j;
}
}
我初学者,不懂,乱编的,谁能给我编一个啊
如果你所说的 编码是 字符串的内码的话,
下面的代码应该是你所要的,
我这边测试通过.
using System;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string s = Console.ReadLine();
string s2 = Console.ReadLine();
int n = int.Parse(s2);
Console.WriteLine(Method(s, n));
Console.Read();
}
public static string Method(string s, int n)
{
int i;
byte[] buf = Encoding.ASCII.GetBytes(s);
for (i = 0; i < buf.Length; i++)
{
buf[i] += (byte)n;
}
return Encoding.ASCII.GetString(buf);
}
}
}
using system;
class MyCode
{
static void Main()
{
string s="";
int n;
n=In