473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Search Strings

How can i search within a string say a description of items and would like the program to search for matching words in any order but they should relate e.g. consider this description: CEMENT AFRISAM 50KG SATCHETS....
i would want a user to lets say type in the words "SATCHETS CEMENT", the search code should be able to list all descriptions that have SATCHETS AND CEMENT in one line.
Mar 5 '10 #1
11 1666
tlhintoq
3,525 Expert 2GB
Loops within loops checking all the suspect words against all the strings you want to search. Making use of the String.Contains method.

http://msdn.microsoft.com/en-us/libr....contains.aspx
Mar 5 '10 #2
i m trying that but its not coming alright, i might be missing something do you have a sample code?
Mar 5 '10 #3
Christian Binder
218 Expert 100+
Maybe you first show us what you've tried (code) and tell us the problem you're facing with your code. So I could help you finding the "something" you're missing.
Mar 5 '10 #4
ThatThatGuy
449 Expert 256MB
you can use regular expressions for checking the existence of the word in a string
with expression as ".*SATCHETS CEMENT*." which will search for the word in string and return whether the word exists....

have a look at the tutorial below if you need any help
http://msdn.microsoft.com/en-us/libr...95(VS.80).aspx is a way where you can search
Mar 5 '10 #5
this was an error i have re entered it below.
Mar 9 '10 #6
Expand|Select|Wrap|Line Numbers
  1. char[] splitchar = { ' ' };
  2.             string[] str = txtstocksearch.Text.Split(splitchar);
  3.             foreach (string item in str)
  4.             {
  5.                 SqlDataAdapter adp = new SqlDataAdapter("select * from stock where stock_description like '%" + item + "%'  , connection.connect());
  6.  
  7.  
  8.             DataSet ds = new DataSet();
  9.             adp.Fill(ds);
  10.             DataTable dt = ds.Tables[0];
  11.             dataGridView2.RowHeadersVisible = false;
  12.             dataGridView2.DataSource = dt;
  13.             dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
  14.             connection.connect ().Close();
Mar 9 '10 #7
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 9 '10 #8
jkmyoung
2,057 Expert 2GB
SqlDataAdapter adp = new SqlDataAdapter("select * from stock where stock_description like '%" + item + "%' , connection.connect());




You want something like
select * from stock where
stock_description like '%" + item + "%' AND
stock_description like '%" + item2 + "%' AND
stock_description like '%" + item3 + "%' ....
correct?

Create the query string beforehand. For each item beyond the first, add:

"AND \n stock_description like '%" + item + "%'

Then do your query.
Mar 9 '10 #9
I seem to have found a lead. i enabled my fulltext indexing on SQL and the problem ha been greatly minimised. however ther is still one annoying problem. how do you pass wildcards from a textbox into the select statment. e.g when in sqladmin, it is easier to type a command like select * from a where contains(b,' "cem* " '), here it will list everything that starts with cem. however, when in c# how do i incorporate the wildcard * to my text box. if i use select * from a where contains(b,' " + textbox1.tex + " *') nuthing happends
Mar 11 '10 #10
Christian Binder
218 Expert 100+
Maybe you should use
Expand|Select|Wrap|Line Numbers
  1. string command = "SELECT * FROM a WHERE CONTAINS(b, ' \"" + textBox1.Text+ "*\" ')";
  2.  
Notice the underlined \"
Mar 11 '10 #11
thank you very much. it seems to be behaving....
Mar 11 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
7
by: pyluke | last post by:
I'm parsing LaTeX document and want to find lines with equations blocked by "\", but not other instances of "\" so, in short, I was to match "\" to add to this, I also don't want lines that...
11
by: Bob Rock | last post by:
Hello, I have an array of strings and need to find the matching one with the fastest possible code. I decided to order the array and then write a binary search algo. What I came up with is the...
4
by: Daryl Lee | last post by:
I am trying to locate all lines in a suite of files with quoted strings of particular lengths. A search pattern like r'".{15}"' finds 15-character strings very nicely. But I have some very long...
2
by: parasuram | last post by:
Hi friends ............. this is a question regarding the data structures trees Pleas post it if possible with in 2 days I will thankful if some body could help doing this. Operating...
0
by: deeak | last post by:
Hi All, I have set of strings in the db2 table and two range keys to search. I have to finds strings the table which would be in between the range of keys defined. Strings in the colum to...
14
by: S | last post by:
Any idea on how I would be able to do a search within C# that does ranges or words For example I want to search for Chicken in the string string s1 = "This is Great Chicken";
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.