473,770 Members | 4,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse a search string

Does anybody have any code that will take a search string and parse it in to
the appropriate parts?

For instance: +google -news -bush

TIA - J.
Feb 1 '08 #1
2 2352
Not sure why you can'yt just split on space, then evaluate each to see what
the first character is and if its minus sign do one thing, else do something
if its a plus, or do something if its neither

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Mufasa" <jb@nowhere.com wrote in message
news:eA******** ******@TK2MSFTN GP02.phx.gbl...
Does anybody have any code that will take a search string and parse it in
to the appropriate parts?

For instance: +google -news -bush

TIA - J.


Feb 1 '08 #2
Mufasa wrote:
Does anybody have any code that will take a search string and parse it in to
the appropriate parts?

For instance: +google -news -bush
For inspiration see below.

Arne

=============== =============== =============== =============

public static void ParseSplit(stri ng s)
{
string[] parts = s.Split(" ".ToCharArray() );
foreach(string part in parts)
{
if(part[0] == '+')
{
Console.WriteLi ne("Include : " + part.Substring( 1));
}
else if(part[0] == '-')
{
Console.WriteLi ne("Exclude : " + part.Substring( 1));
}
}
}
private static readonly Regex incl = new Regex(@"(?:\+)( \w+)(?: |$)",
RegexOptions.Co mpiled);
private static readonly Regex excl = new Regex(@"(?:\-)(\w+)(?: |$)",
RegexOptions.Co mpiled);
public static void ParseRegex(stri ng s)
{
foreach(Match m in incl.Matches(s) )
{
Console.WriteLi ne("Include : " + m.Groups[1].Value);
}
foreach(Match m in excl.Matches(s) )
{
Console.WriteLi ne("Exclude : " + m.Groups[1].Value);
}
}

Feb 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14635
by: Alex Hunsley | last post by:
I've using the csv module to parse a string, not a file. So how do I make a string look like a file so I can call csv.reader() with it? An an example, I'd like to call something like: csvReader = csv.reader("1,2,3,4") ... but this direct attempt won't work as it expects a file or a handle...
10
19530
by: Ryan Cooper | last post by:
Can anyone give me an idea or better yet, a code sample, demonstrating how to parse a JPEG header and search the header for markers located in the stream? Basically, I need to analyze an uploaded JPEG file, search for the markers C2, C6 and CA in the stream, and then set a variable of some sort to specify whether or not these markers are present. (The reason I need these is to determine whether the JPEG is in "Progressive" or "Baseline"...
1
2021
by: Charlie T | last post by:
hello, I need a little guidance here... I am tring to parse out an XML file, but with some restrictions. here is my XML FILE: ---------XML----------- <XML> <Cam name="01"> <loc>Newport</loc>
1
2893
by: kfrost | last post by:
I'm connecting to an exchange public folder and pulling out contacts via XML. I can use the .responseText to view the text string. The response from Exchange in this string is formatted in XML. I'm trying to figure out what I could use to parse the info out of the response because I need to write the values to SQL. Here's the code: try {
10
3202
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from the output, save for those that manage color codes or text presentation (in short, the ones that are ESChttp://fd0man.theunixplace.com/Tmud.tar which contains the code in question. In short, the information is coming in over a TCP/IP socket that...
1
5566
by: ozzii | last post by:
Hi, Does anybody know how to parse the name value pairs in a querystring contained in a variable with asp? for those of you who might be confused, what i am trying to do is basically I have a recordset paging script generated for a search page. I want to read all the search criteria in the querystring of this paging script into one variable and then parse it at the other end. The idea behind this is to avoid displaying the entire...
6
9293
by: Cross | last post by:
Is there anyone who knows how to parse a windows shortcut (lnk file) on the start menu? How hard could it be, it is just a few values, like Target file, Icon file... I search for in on Internet for a while, but I did not found anything. So what I want is the sourse code for a shortcut parser, written in VB.net if possible (C# would be ok), or at least the specification for how a shortcut (LNK file) is build, so I can writ one myself. ...
17
11328
by: Thomas Kowalski | last post by:
Hi, I would like to know whether someone knows a library or function that parses a string containing 3 double numbers in the form like xxxx.yyyyyyyyy xxxx.yyyyyyyyy xxxx.yyyyyyyyy really fast. Currently I am using "sscanf(line.c_str(), "%lf %lf %lf", &x, &y, &z);" which is kind of slow. Thanks in advance, Thomas Kowalski
11
2354
by: Peter Afonin | last post by:
Hello, I need to parse a string that returns the domain DNS records and to put this data into a DataTable. I don't have much experience in parsing strings, so I'm not aware of the efficient way how to do this. I've found some examples of CSV parser classes, but not sure how to use them in my case. Here is an example of the string: RRs\nsubname: @;priority: 5;address: mail.domainname.net.;rectype:
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.