Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How should this indexof be?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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