Click here to Skip to main content
12,996,709 members (78,126 online)
Rate this:
Please Sign up or sign in to vote.
Hello to all experts.. :) I'm very new in C#(and programming in general), so i apologize if my description isn't as clear as it could be. Here is my wanna-do task :doh: . I have a string let's say:
string final_word="New Bacliff Texas United States";

what i want to do is to check every possible substring of this string for a match in a database.
To be more clear, at first I'll check for the final_word string to the database,if no matches found,I want to search for the string "New Bacliff Country United",if I find a match i want to search for the string "United".If no matches found for both string i want to search for string "New Bacliff Country" and for the string "United States".If a match is found for the "United States". I will keep looking for matches in substrings of the string "New Bacliff Country",which means that i will look for "New Bacliff" and "Country","Bacliff Country" etc.At the end if no matches found for none of the substrings i will search for each word of the string. Keep in mind that i don't know in advance the size of the original string..
I hope i made my point clear.
Any ideas??I don't know what to do split the string create an array and the join array's items?? :((
Thanks for your help in advance!!!
Any answer could help me!!!!
Posted 1-Feb-11 5:19am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you just want to split the string into individual words, then use String.Split or one of its overloads.

If you also want to specifically check for combinations of those words, then create a collection of all word combinations possible from your list of sub-strings.

Here's a fairly good article on generating permutations:[^]
katerinaPapathak 1-Feb-11 11:28am
thank you for your answer but the search for individual words in the strings should be the last step of my procedure...:)
Nishant Sivakumar 1-Feb-11 11:30am
Then do it in reverse. Create a collection of word combinations so that the longer word combinations are on top, and the single word entries come last. Now search top down going through this collection.
katerinaPapathak 1-Feb-11 11:32am
thank you I'll give it a try...
Nishant Sivakumar 1-Feb-11 11:35am
Take a look at this article too:
katerinaPapathak 1-Feb-11 11:43am
my problem is that i don't want every possible combination of the above words, I only want to consider consequtive I don't want to search the database for "Texas United", because they are not consequtive words in the original string. And if for a substring let's say for the substring "United States" i find a match i don't want to include any of the words "United" or "States" in the remaining combinations.
Nishant Sivakumar 1-Feb-11 11:54am
Yeah, it would mean changing your combination generation code to handle that. It actually might make the code easier since you only consider words near each other in the source string.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

To create substrings via regex, see here[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170609.2 | Last Updated 1 Feb 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100