Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:27:43+00:00 2026-05-31T20:27:43+00:00

environment: microsoft visual studio 2008 c# How do I get the index of a

  • 0

environment: microsoft visual studio 2008 c#

How do I get the index of a whole word found in a string

string dateStringsToValidate = "birthdatecake||birthdate||other||strings";
string testValue = "birthdate";

var result = dateStringsToValidate.IndexOf(testValue);

It doesn’t have to be the way i did it either, for example, would it be better to use regular expressions or other methods?

Update:
The word is birthdate not birthdatecake. it doesn’t have to retrieve the match but the index should find the right word. i don’t think IndexOf is what i’m looking for then. Sorry for being unclear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:27:44+00:00Added an answer on May 31, 2026 at 8:27 pm

    Use regular expressions for this

      string dateStringsToValidate = "birthdatecake||birthdate||other||strings";
      string testValue = "strings";
      var result = WholeWordIndexOf(dateStringsToValidate, testValue);
    
    // ...
    
    public int WholeWordIndexOf(string source, string word, bool ignoreCase = false)
    {
      string testValue = "\\W?(" + word + ")\\W?";
    
      var regex = new Regex(testValue, ignoreCase ? 
             RegexOptions.IgnoreCase : 
             RegexOptions.None);
    
      var match = regex.Match(source);
      return match.Captures.Count == 0 ? -1 : match.Groups[0].Index;
    }
    

    Learn more about regex options in c# here

    Another option, depending on your needs, is to split the string (as I see you have some delimiters). Please note the index returned by the this option is the index by word count, not character count (In this case, 1, as C# has zero based arrays).

      string dateStringsToValidate = "birthdatecake||birthdate||other||strings";
      var split = dateStringsToValidate.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
      string testValue = "birthdate";
      var result = split.ToList().IndexOf(testValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create the webpart in Visual studio 2010/2008 environment with microsoft given
My coding environment: the compiler is Microsoft Visual Studio C++ 2008. Okay, I have
My current preferred C++ environment is the free and largely excellent Microsoft Visual Studio
I'm using Visual Studio 2008 with Microsoft test tools. I need to access a
When I return from debug mode, my visual studio 2008 environment takes a really
Environment: C# projects, Visual studio 2008, C#, .Net 3.5, MSBuild Objective: Run my own
Environment Visual Studio 2008 SP1 Visual C# WPF Application Project .NET Framework 3.5 Problem
I am working on Microsoft Visual Studio environment. I came across a strange behavior
I'm struggling with setting my scons environment variables for visual studio 2008. Normally I
I'm very beginner for developping. environment is .. Windows XP Professional SP3 Microsoft Visual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.