Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 database string
Hello to all experts.. Smile | :) 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 D'Oh! | :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?? Cry | :((
Thanks for your help in advance!!!
Any answer could help me!!!!
Posted 1-Feb-11 6:19am
Rate this: bad
good
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.
 
[Update]
----------
Here's a fairly good article on generating permutations:
 
http://msdn.microsoft.com/en-us/library/aa302371.aspx[^]
  Permalink  
v3
Comments
katerinaPapathak at 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 at 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 at 1-Feb-11 11:32am
   
thank you I'll give it a try...
Nishant Sivakumar at 1-Feb-11 11:35am
   
Take a look at this article too:
 
http://msdn.microsoft.com/en-us/library/aa302371.aspx
katerinaPapathak at 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.
Nishant Sivakumar at 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
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 309
2 BillWoodruff 174
3 /\jmot 160
4 Suraj Sahoo | Coding Passion 160
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 1 Feb 2011
Copyright © CodeProject, 1999-2014
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