Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I have a problem which I do not understand. Here is my code:

String input = "3 days ago" String firstCharacter = input[0].ToString(); //Returns 3 int firstCharacter = (int)input[0]; //Returns 51 

Why does it return 51?

PS: My code comes from this thread: How to get first char of a string?How to get first char of a string?

More information:

In case that input = "5 days ago", then int firstCharacter is 53. 

I have a problem which I do not understand. Here is my code:

String input = "3 days ago" String firstCharacter = input[0].ToString(); //Returns 3 int firstCharacter = (int)input[0]; //Returns 51 

Why does it return 51?

PS: My code comes from this thread: How to get first char of a string?

More information:

In case that input = "5 days ago", then int firstCharacter is 53. 

I have a problem which I do not understand. Here is my code:

String input = "3 days ago" String firstCharacter = input[0].ToString(); //Returns 3 int firstCharacter = (int)input[0]; //Returns 51 

Why does it return 51?

PS: My code comes from this thread: How to get first char of a string?

More information:

In case that input = "5 days ago", then int firstCharacter is 53. 
Post Closed as "Duplicate" by Wiktor Stribiżew, Win, MethodMan, Heretic Monkey, Drew
edited tags
Link
Wiktor Stribiżew
  • 631k
  • 41
  • 502
  • 632
Source Link
Happy Bird
  • 1.2k
  • 2
  • 11
  • 29

string[0] get first character from string

I have a problem which I do not understand. Here is my code:

String input = "3 days ago" String firstCharacter = input[0].ToString(); //Returns 3 int firstCharacter = (int)input[0]; //Returns 51 

Why does it return 51?

PS: My code comes from this thread: How to get first char of a string?

More information:

In case that input = "5 days ago", then int firstCharacter is 53.