string search

Apr 7, 2015 at 6:29pm
How do you search a string so that if the string begins with the letter "b" then I can know whether a student will be undergrad or postgrad? So basically I need to know if the string begins with "b" or not.

Apr 7, 2015 at 6:36pm
Strings are like arrays.

string grade = "Beaver";

If you want to check the first letter. Its simply grade[0]. grade[0] in this case is "b". grade[1] is "e" and so on and so forth.

1
2
3
4
if(grade[0] == 'b')
{
    //stuff
}
Last edited on Apr 7, 2015 at 6:37pm
Apr 7, 2015 at 7:05pm
Thanks alot
Topic archived. No new replies allowed.