Solved

How should this indexof be?

Posted on 2009-07-09
2
298 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
[X]
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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MailAddress in vb 4 36
LINQ Select all records by MAX data syntax help 1 30
c# ftp code 3 33
asp.net repeater 2 15
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…

726 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