字母转换

w09123 2009-12-11 12:44:33
求一个函数,将字母‘a’转为‘d’,‘b’转为‘e’,‘A’转为‘D’,‘B’转为‘E’,其他的依次类推,要用VB2005写哦
...全文
239 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jave.Lin 2009-12-12
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 w09123 的回复:]
楼上的提供的答案都很好,可是我要的是VB的
[/Quote]

看到楼主这回答,我笑到扒在地上,“谁可以扶我起来啊,嘎嘎嘎嘎~~~”
w09123 2009-12-12
  • 打赏
  • 举报
回复
楼上的提供的答案都很好,可是我要的是VB的
gghlkk 2009-12-11
  • 打赏
  • 举报
回复
(z|Z)=>{?}
silentwins 2009-12-11
  • 打赏
  • 举报
回复
Convert.ToChar(Convert.ToInt16('A')+3)
liherun 2009-12-11
  • 打赏
  • 举报
回复
private char zhuanhuan(char c)
{
int i = c;
return Convert.ToChar(i + 3);
}
tianliang1 2009-12-11
  • 打赏
  • 举报
回复
c语言课后练习题。。。。呵呵
wuxixujia 2009-12-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liherun 的回复:]
C# codeprivatechar zhuanhuan(char c)
{int i= c;return Convert.ToChar(i+3);
}
[/Quote]
正解
cacagege 2009-12-11
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str1 = "abcdxyzABCDXYZ";
string str2 = GetString(str1);

Console.WriteLine(str2);
Console.Read();

}
private static string GetString(string strTarget)
{
StringBuilder sb = new StringBuilder();
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] byteStr = ascii.GetBytes(strTarget);
int c;
foreach (byte code in byteStr)
{
if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122))
{
c = code + 3;
if (c > 90 && c < 94)
{
c = (c - 90) + 65;
}
if (c > 122 && c < 126)
{
c = (c - 122) + 97;
}
sb.Append(Convert.ToChar(c));
}
}
return sb.ToString();
}
}

}
colin_liying 2009-12-11
  • 打赏
  • 举报
回复
string str="abcde";
for (int i = (int)'z'; i >= (int)'a';i-- )
{
char old1 = (char)i;
char new1 = (char)(i + 1);
str=str.Replace(old1, new1);
}
for (int i = (int)'Z'; i >= (int)'A'; i--)
{
char old1 = (char)i;
char new1 = (char)(i + 1);
str = str.Replace(old1, new1);
}
eHuaTian 2009-12-11
  • 打赏
  • 举报
回复
楼上的解决方法均可行
mbh0210 2009-12-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yfqvip 的回复:]
如果当值为z的时候,需要回头再从a计算的话,好像只有用if判断了,否则直接:
VB codePrivateFunction ConvertToX(ByVal cAs Char)As Char
Return CChar((c+3))End Function
[/Quote]

yes
,估计是作业
满衣兄 2009-12-11
  • 打赏
  • 举报
回复
如果当值为z的时候,需要回头再从a计算的话,好像只有用if判断了,否则直接:
Private Function ConvertToX(ByVal c As Char) As Char 
Return CChar((c + 3))
End Function
as452181826 2009-12-11
  • 打赏
  • 举报
回复
char[] a = new char[127];

for (int i = 0; i < a.Length; i++)
{
a[i] = Char.Parse( Console.ReadLine());
if (a[i] >= 'A' && a[i] <= 'Z')
a[i] += Convert.ToChar(3);
if (a[i] >= 'a' && a[i] <= 'z')
a[i] += Convert.ToChar(3);
Console.WriteLine(a[i]);
}
wartim 2009-12-11
  • 打赏
  • 举报
回复
            
char c = (char)(('a' + 3) % 'z' + ('a' + 3) / 'z' * ('a' - 1)); // 'd'
char c2 = (char)(('x' + 3) % 'z' + ('x' + 3) / 'z' * ('a' - 1)); // 'a'

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧