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

  • Home
  • SEARCH
  • 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 3451802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:11:05+00:00 2026-05-18T09:11:05+00:00

I have to search for the first match of any string in an string

  • 0

I have to search for the first match of any string in an string array in a textbox starting from a certain position. Like if I have this string array:

string[] s = { "RTS", "RTL" };

And this code:

LDA #$43
STA $1000,x
CMP $00
BEQ .main
.return
RTS
.main
add $01
RTL

It should return RTS since that’s the first match (not the RTL). How can I do this? Additionally, would there be a better way of doing this rather than using an array?

Edited since I gave a bad example of what I was trying to do.

  • 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-18T09:11:06+00:00Added an answer on May 18, 2026 at 9:11 am

    There may be algorithms to do this efficiently, but I don’t know of any. Fortunately this can be represented easily in code through basic searching.

    var str = textbox.Text;
    var words = new[] { "RTS", "RTL" };
    var result = words.AsParallel()
                      .Select(Word => new { Word, Index = str.IndexOf(Word) })
                      .Where(p => p.Index >= 0)
                      .OrderBy(p => p.Index)
                      .Select(p => p.Word)
                      .FirstOrDefault();
    if (result == null)
    {
        // no match
    }
    else
    {
        // match
    }
    

    This should be able to run in parallel fine. If not, remove AsParallel().


    An alternative approach is to iterate through the string checking for the words picking the first that occurs. It should perform better than the first.

    var result = Enumerable.Range(0, str.Length)
                           .SelectMany(i => words.Where(w => str.Substring(i)
                                                                .StartsWith(w)))
                           .FirstOrDefault();
    

    If you’d want the best in terms of efficiency, you’d have to write up a state machine for this but would be very complicated for a simple search of 2 (or more) words.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search form. I would like when someone type the term, first
Let's say I have a multi-line string like this: STARTFRUIT banana ENDFRUIT STARTFRUIT avocado
I have a regex to match middle names that looks like this : first_name
I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and
I have already implemented a functionallity, when keeper automatically moves using breadth first search
I have xpath page.search(//table[@class='campaign']//table) which returns two tables. I need to choose only first
I currently have a JQGrid implementation. The first time I run the search it
first of all I'm using MySql. I have to create a advance search field
i have search at this websit : https://stackoverflow.com/search?page=2&tab=relevance&q=nsarraym%20objectatindex%20index%205%20beyond%20bounds%20for%20empty%20array%27 but the solve no suit me.
I have search through the web to figure this out but no luck. I

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.