M Mattias Sjögren Jan 9, 2004 #2 How can I convert a string to a ascii code in c#? Click to expand... System.Text.Encoding.ASCII.GetBytes(theString); Mattias
How can I convert a string to a ascii code in c#? Click to expand... System.Text.Encoding.ASCII.GetBytes(theString); Mattias
J Jon Skeet [C# MVP] Jan 9, 2004 #3 ally said: How can I convert a string to a ascii code in c#? Click to expand... Do you mean a single character within a string? Just get the character, e.g. string h = "hello"; char c = h[3]; Now the character is the Unicode value, but all ASCII values are the same in Unicode. So, for instance: int i = c; will make i be the ASCII code for 'l'. (Converting to int isn't really necessary, but perhaps makes it clearer.)
ally said: How can I convert a string to a ascii code in c#? Click to expand... Do you mean a single character within a string? Just get the character, e.g. string h = "hello"; char c = h[3]; Now the character is the Unicode value, but all ASCII values are the same in Unicode. So, for instance: int i = c; will make i be the ASCII code for 'l'. (Converting to int isn't really necessary, but perhaps makes it clearer.)