【问题标题】:What is the charCodeAt() equivalent in C#?C# 中的 charCodeAt() 等价物是什么?
【发布时间】:2014-03-21 05:22:06
【问题描述】:
C# 中的 charCodeAt() 等价物是什么?
当前代码:
string outString="";
for (var i = 0; i < inpString.Length; i++)
{
outString += inpString.charCodeAt(i).toString(); //i need to replaced charCodeAt(i) with equalent c# code
}
如何在 C# 中做到这一点?
【问题讨论】:
标签:
c#
javascript
asp.net
c#-4.0
【解决方案1】:
试试这个
string outString="";
for (var i = 0; i < inpString.Length; i++)
{
outString+= ((int)inpString[i]).ToString();
}
【解决方案2】:
以下将返回 3,因为索引从 0 开始的第四个字符。
string result = "012345";
Response.Write(result.ToCharArray()[3]); ;
所以你的情况
string outString="";
for (var i = 0; i < inpString.Length; i++)
{
outString += inpString.ToCharArray()[3]; //i need to replaced charCodeAt(i) with equalent c# code
}