i Am a StuDent原代码 结果:j Bn b TuvEfou将 for(int i=(int)'Z';i>=(int)'A';i--) 改为 for(int i=(int)'A';i <=(int)'Z’;i++) 结果:j [n b [uv[fou因为第二个循环执行的是 A 替换为 B B 替换为 C 。。 Y 替换为 Z Z 替换为 [还是我说的原因 - - 我测试了
using System; class program { static void Main() { string str="i am a student"; for(int i=(int)'a';i <=(int)'z';i++) { char oldstr=(char)i; char newstr=(char)(i-1); str=str.Replace(oldstr,newstr);
从a 到z ,a变成b ,所有的b(包括a变过来的) 都变成c ,... ... 最后所有字母都变成 z的后面 { 了.using System;
class program
{
static void Main()
{
string str="i am a student";
for(int i=(int)'a';i <=(int)'z';i++)
{
char oldstr=(char)i;
char newstr=(char)(i-1);
str=str.Replace(oldstr,newstr);
}
for(int i=(int)'A';i <=(int)'Z';i++) {
char oldstr=(char)i;
char newstr=(char)(i-1);
str=str.Replace(oldstr,newstr);
}
Console.WriteLine(str);
}
}
这样也可以,不过就是A前面一个字符会~~
结果:j Bn b TuvEfou将
for(int i=(int)'Z';i>=(int)'A';i--)
改为
for(int i=(int)'A';i <=(int)'Z’;i++) 结果:j [n b [uv[fou因为第二个循环执行的是
A 替换为 B
B 替换为 C
。。
Y 替换为 Z
Z 替换为 [还是我说的原因 - - 我测试了
class program
{
static void Main()
{
string str="i am a student";
for(int i=(int)'a';i <=(int)'z';i++)
{
char oldstr=(char)i;
char newstr=(char)(i-1);
str=str.Replace(oldstr,newstr);
}
for(int i=(int)'A';i <=(int)'Z';i++) {
char oldstr=(char)i;
char newstr=(char)(i-1);
str=str.Replace(oldstr,newstr);
}
Console.WriteLine(str);
}
}
的输出结果是 h `1` rstcdms
而下面的程序
using System;
class program
{
static void Main()
{
string str="i am a student";
for(int i=(int)'a';i <=(int)'z';i++)
{
char oldstr=(char)i;
char newstr=(char)(i+1);
str=str.Replace(oldstr,newstr);
}
for(int i=(int)'A';i <=(int)'Z';i++) {
char oldstr=(char)i;
char newstr=(char)(i+1);
str=str.Replace(oldstr,newstr);
}
Console.WriteLine(str);
}
}
的输出结果是{ {{ { {{{{{{{
我刚试过的
我想知道为什么-1加密只能从 小 到 大. +1加密只能从 大 到 小
麻烦各位大虾帮忙给小弟个原因