简体   繁体   English

C#中的charCodeAt()等价物是什么?

[英]What is the charCodeAt() equivalent in C#?

What is the charCodeAt() equivalent in C#? C#中的charCodeAt()等价物是什么?

Current Code: 现行代码:

   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
    }

How can i do this in C#? 我怎样才能在C#中做到这一点?

Try out this 试试这个

string outString="";

for (var i = 0; i < inpString.Length; i++)

{

outString+= ((int)inpString[i]).ToString();

}

The following will return 3 the fourth character since index starts at 0. 以下将返回3第四个字符,因为索引从0开始。

    string result = "012345";
    Response.Write(result.ToCharArray()[3]); ;

So in your case 所以在你的情况下

string outString="";
for (var i = 0; i < inpString.Length; i++)
{
outString += inpString.ToCharArray()[3]; //i need to replaced charCodeAt(i) with equalent c# code
}

If you want to get the unicode character at the specified character in a string, you might want to check out Convert.toUint16(char) , Convert.toUint32(char) methods. 如果要在字符串中的指定字符处获取unicode字符,可能需要检查Convert.toUint16(char)Convert.toUint32(char)方法。

foreach(var a in inputstring)
    Console.Write("{0} ", Convert.ToUInt16(a).ToString("X4"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM