Solved

How should this indexof be?

Posted on 2009-07-09
2
296 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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