Convert a String to ASCII

The sample code is a simple function written in C# that converts a given string to it's ASCII value.

Although the function returns a string, the string is actually the ASCII equivalent of the input.


string StringToASCII(string input)
{
int asc = 0;
int i = 0;
char c;
for (i = 0; i < input.Length; i++)
{
c = input[i];
asc = asc + input[i];
}
return Convert.ToString(asc);
}


Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: