c# - 通过字符串的某个位置获取ascii的char
问题描述
我想通过 c# 上字符串的某个位置获取 ascii 的字符,但我无法以正确的方式到达。
代码:
string Str;
string StrEnd;
int Clave = 0;
Str = txtStr.Text;
Clave = Convert.ToInt32(txtCv.Text);
for (int i = 0; i == Str.Length - 1; i++)
{
StrEnd = (char)Encoding.ASCII.GetBytes(Str[index: i]) + Clave;
}
对于EG。
Str = "ABC"
,var Clave = 1
然后string StrEnd
会是这个样子"BCD"
。
另一个例子是......
Str = "Hola"
,Clave = 2
那么StrEnd = "Jqnc"
如果还不清楚,请告诉我。
提前致谢。
解决方案
它缺少 Linq 解决方案:(
如果使用的 C# 版本不允许使用 auto [out] 参数,请添加int key = 0;
)。
string Str = "Hola";
if (int.TryParse(txtCv.Text, NumberStyles.Integer, CultureInfo.CurrentCulture, out int key))
{
string StrEnd = string.Join("", Str.Select(c => (char)(c + key)));
}
与key == 2
:StrEnd = "Jqnc"
推荐阅读
- elasticsearch - 从 ES 2.1 到 ES 7.2 的转储映射
- javascript - jQuery 数据属性改变和影响 CSS
- xpath - XPath 兄弟返回空
- linux - 在 Linux 上使用 Schwab StreetSmart Edge Cloud - Citrix 错误
- c++ - 无法将右值引用函数与 GCC 匹配
- linux - 如何从 key=value 格式的文件中仅获取选定的行?
- json - _CastError(“客户端”类型不是“列表”类型的子类型
' 在类型转换中) - c# - 是否可以使用 Roslyn 构建 ASP.Net Core Web 应用程序?
- python - 范围类的计数方法的目的是什么?
- excel - 在excel中转置日期以包含标题行