简体   繁体   中英

What is the charCodeAt() equivalent in C#?

What is the charCodeAt() equivalent in C#?

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#?

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.

    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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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