Solved

How should this indexof be?

Posted on 2009-07-09
2
294 Views
Last Modified: 2012-05-07
If I add Andersson I get it right
But if I add aaaaaa its not right


 if (contact[i].LastName.ToLower().IndexOf(letter.ToString().ToLower())== 0)


What I am after is that every word that starts with for example A should be true. But in the case of aaaaa I get the number 4 back in debug mode. How should my if statment be to be like I want to happen?
0
Comment
Question by:Mickeys
2 Comments
 
LVL 15

Accepted Solution

by:
crisco96 earned 250 total points
ID: 24817456
If you only care if the name starts with the letter do the following:
 if (contact[i].LastName.ToLower().StartsWith(letter.ToString().ToLower()))

Open in new window

0
 
LVL 8

Assisted Solution

by:InternalStatic
InternalStatic earned 250 total points
ID: 24817477
You could just use the StartsWith method, like this:
if(contact[i].LastName.ToLower().StartsWith("a"))
Hope it helps,
Nate
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now