convert textbox character size in to kb in c#PJParmar Jagdish12yAsked Dec 26, 2014, 2:47 AM1.1kLearn iOS Programmingplease give ne answer
Manish Kumar Choudhary12y agoPosted Dec 26, 2014, 3:07 AMAre you saying you have something like this: string s = "48656c6c6f2c20776f726c6421"; and you want these values as a byte array? Then: public IEnumerable GetBytesFromByteString(string s) { for (int index = 0; index < s.Length; index += 2) { yield return Convert.ToByte(s.Substring(index, 2), 16); } }Usage:string s = "48656c6c6f2c20776f726c6421";var bytes = GetBytesFromByteString(s).ToArray();Note that the output ofConsole.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(bytes));is Hello, world!0
Manish Kumar ChoudharyPosted Dec 26, 2014, 3:07 AM
Are you saying you have something like this:
string s = "48656c6c6f2c20776f726c6421";
and you want these values as a byte array? Then:
public IEnumerable GetBytesFromByteString(string s) {
for (int index = 0; index < s.Length; index += 2) {
yield return Convert.ToByte(s.Substring(index, 2), 16);
}
}
Usage:
string s = "48656c6c6f2c20776f726c6421";
var bytes = GetBytesFromByteString(s).ToArray();
Note that the output of
Console.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(bytes));
is
Hello, world!