• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

How do i compare first letter with my string?

I want to find a letter in my string.

Let say I have a string with an "A"
Then I have another string. I want this to see if the first letter in the string is "A"

Andersson  //This one is true. First letter A
Walter    //This one is false. First letter W

What letter comes into my method is never known. Sometimes an A sometimes B and so on
1 Solution

string x;
char someChar;
x = "Anderson";
someChar = 'A';
if (x.IndexOf(someChar) == 0)

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now