C#将string字符串中每一个字符的ascii码值加上某个值后输出,这怎么写?

C#将string字符串中每一个字符的ascii码值加上某个值后输出,这怎么写?

string newStr = "";
string text = "abcde";
foreach (char c in text.ToCharArray()) 
{
    newStr += (int)c + 5;    //每个字符的ASCII加上5
}

追问

不是,我需要的是输出结果还是一个字符串,比如说abcd,变成cdef

追答string newStr = "";
string text = "abcde";
foreach (char c in text.ToCharArray()) 
{
    newStr += Encoding.ASCII.GetString(new byte[] { (byte)(c + 5) });
}
//newStr=fghij

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-03-24
string ss = "qwertyuio";
int i = 12;
foreach (var item in ss)
{
int zqq = item + i;
Console.WriteLine(zqq + "=");
}
相似回答