Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.

[Update]
----------
Here's a fairly good article on generating permutations:

http://msdn.microsoft.com/en-us/library/aa302371.aspx[^]
 
Share this answer
 
v3
Comments
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...:)
Nish Nishant 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...
Nish Nishant 1-Feb-11 11:35am    
Take a look at this article too:

http://msdn.microsoft.com/en-us/library/aa302371.aspx
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 words..eg. 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.
To create substrings via regex, see here[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900