473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting MSSQL FTS parsing function from VBScript to C#

Hi all,

I'm here to humbly request some "gimme" help from the group. I discovered
the infinite wonders of VS.NET 2005 and ASP.NET 2.0 at Tech Ed a couple of
weeks ago, and since returning to work I haven't looked back. Unfortunately
I still have some critical functions that I originally created as vbscript
functions. I need these functions to do my work. Before I can transition
entirely to C#-based ASP.NET sites, I need these functions to be translated
to C# syntax.

I've managed most on my own. The most difficult to translate is a function I
made to prepare a text string so that it is in the proper format demanded by
SQL Server's awesome Full Text Search capability.

Ideally, someone knows of an analogous function that's already been hacked
up in C#. I'd imagine this particular wheel has been reinvented a few
billion times.

Barring that, I'm hoping some of the sharper Csharpers will hold my hand and
help me translate the function to C#. It's straight string manipulation
stuff, and appears below. Thanks in advance for any help you can offer.

Ken Fine
University of Washington

Function CreateSQLContai nsString(s, requireAllWords )
dim i, start, result, sLen, conjunction, token, fSeparator
result = ""
start = 1
sLen = Len(s)
fSeparator = False

If requireAllWords Then
conjunction = " AND"
Else
conjunction = " OR"
End If

For i = 1 to sLen
ch = Mid(s, i, 1)

If (ch="""") Then
i = i + 1
While (i < sLen AND Mid(s,i,1) <> """")
i = i + 1
Wend
End If

If (ch=" " or i = sLen) Then
token = Trim(Mid(s, start, i-start+1))
utoken = UCase(token)
If start = 1 Then
result = token
ElseIf (utoken = "AND" or utoken="OR" or utoken="NEAR") Then
result = result + " " + utoken
fSeparator = TRUE
Else
If fSeparator = FALSE Then
result = result + conjunction
End If
result = result + " " + token
fSeparator = FALSE
End If
start = i + 1
End If
Next
CreateSQLContai nsString = result
End Function
Nov 17 '05 #1
2 1786
just a straight port really...

string CreateSqlContai nsString ( string s, bool requireAllWords )
{
string conjunction = requireAllWords ? " AND " : " OR " ;
string ch;
string token;
System.Text.Str ingBuilder result = new
System.Text.Str ingBuilder();
bool bSeperator = false;

int start =1;

for ( int i = 0; i < s.Length-1; i++ )
{
ch = s.Substring ( i, 1 );

if ( ch == "\"" )
{
i++;
while ( i < s.Length && s.Substring(i,1 ) != "\"" )
{
i++;
}
}

if ( ch == " " )
{
token = s.Substring ( start, i-start+1 );
string uToken = token.ToUpper() ;
if ( start == 1 )
{
result = new System.Text.Str ingBuilder();
result.Append(t oken);
}
else if ( uToken == "AND" || uToken == "OR" || uToken ==
"NEAR" )
{
result.Append ( " " + uToken );
bSeperator = true;
}
else
{
if ( !bSeperator )
{
result.Append ( conjunction );
}
result.Append ( " " + token );
bSeperator = false;
}
start = i+1;
}

}

return result.ToString ();

}
<ke*****@u.wash ington.edu> wrote in message
news:uv******** ******@tk2msftn gp13.phx.gbl...
Hi all,

I'm here to humbly request some "gimme" help from the group. I discovered
the infinite wonders of VS.NET 2005 and ASP.NET 2.0 at Tech Ed a couple of
weeks ago, and since returning to work I haven't looked back.
Unfortunately I still have some critical functions that I originally
created as vbscript functions. I need these functions to do my work.
Before I can transition entirely to C#-based ASP.NET sites, I need these
functions to be translated to C# syntax.

I've managed most on my own. The most difficult to translate is a function
I made to prepare a text string so that it is in the proper format
demanded by SQL Server's awesome Full Text Search capability.

Ideally, someone knows of an analogous function that's already been hacked
up in C#. I'd imagine this particular wheel has been reinvented a few
billion times.

Barring that, I'm hoping some of the sharper Csharpers will hold my hand
and help me translate the function to C#. It's straight string
manipulation stuff, and appears below. Thanks in advance for any help you
can offer.

Ken Fine
University of Washington

Function CreateSQLContai nsString(s, requireAllWords )
dim i, start, result, sLen, conjunction, token, fSeparator
result = ""
start = 1
sLen = Len(s)
fSeparator = False

If requireAllWords Then
conjunction = " AND"
Else
conjunction = " OR"
End If

For i = 1 to sLen
ch = Mid(s, i, 1)

If (ch="""") Then
i = i + 1
While (i < sLen AND Mid(s,i,1) <> """")
i = i + 1
Wend
End If

If (ch=" " or i = sLen) Then
token = Trim(Mid(s, start, i-start+1))
utoken = UCase(token)
If start = 1 Then
result = token
ElseIf (utoken = "AND" or utoken="OR" or utoken="NEAR") Then
result = result + " " + utoken
fSeparator = TRUE
Else
If fSeparator = FALSE Then
result = result + conjunction
End If
result = result + " " + token
fSeparator = FALSE
End If
start = i + 1
End If
Next
CreateSQLContai nsString = result
End Function

Nov 17 '05 #2
Thank you +very+ much, Dan. I owe you one.

Let me know if you ever need graphics help or writing/editing assistance. In
a past life, I ...

-KF
"Dan Bass" <Not Listed> wrote in message
news:uE******** ******@TK2MSFTN GP15.phx.gbl...
just a straight port really...

string CreateSqlContai nsString ( string s, bool requireAllWords )
{
string conjunction = requireAllWords ? " AND " : " OR " ;
string ch;
string token;
System.Text.Str ingBuilder result = new
System.Text.Str ingBuilder();
bool bSeperator = false;

int start =1;

for ( int i = 0; i < s.Length-1; i++ )
{
ch = s.Substring ( i, 1 );

if ( ch == "\"" )
{
i++;
while ( i < s.Length && s.Substring(i,1 ) != "\"" )
{
i++;
}
}

if ( ch == " " )
{
token = s.Substring ( start, i-start+1 );
string uToken = token.ToUpper() ;
if ( start == 1 )
{
result = new System.Text.Str ingBuilder();
result.Append(t oken);
}
else if ( uToken == "AND" || uToken == "OR" || uToken
== "NEAR" )
{
result.Append ( " " + uToken );
bSeperator = true;
}
else
{
if ( !bSeperator )
{
result.Append ( conjunction );
}
result.Append ( " " + token );
bSeperator = false;
}
start = i+1;
}

}

return result.ToString ();

}
<ke*****@u.wash ington.edu> wrote in message
news:uv******** ******@tk2msftn gp13.phx.gbl...
Hi all,

I'm here to humbly request some "gimme" help from the group. I discovered
the infinite wonders of VS.NET 2005 and ASP.NET 2.0 at Tech Ed a couple
of weeks ago, and since returning to work I haven't looked back.
Unfortunately I still have some critical functions that I originally
created as vbscript functions. I need these functions to do my work.
Before I can transition entirely to C#-based ASP.NET sites, I need these
functions to be translated to C# syntax.

I've managed most on my own. The most difficult to translate is a
function I made to prepare a text string so that it is in the proper
format demanded by SQL Server's awesome Full Text Search capability.

Ideally, someone knows of an analogous function that's already been
hacked up in C#. I'd imagine this particular wheel has been reinvented a
few billion times.

Barring that, I'm hoping some of the sharper Csharpers will hold my hand
and help me translate the function to C#. It's straight string
manipulation stuff, and appears below. Thanks in advance for any help
you can offer.

Ken Fine
University of Washington

Function CreateSQLContai nsString(s, requireAllWords )
dim i, start, result, sLen, conjunction, token, fSeparator
result = ""
start = 1
sLen = Len(s)
fSeparator = False

If requireAllWords Then
conjunction = " AND"
Else
conjunction = " OR"
End If

For i = 1 to sLen
ch = Mid(s, i, 1)

If (ch="""") Then
i = i + 1
While (i < sLen AND Mid(s,i,1) <> """")
i = i + 1
Wend
End If

If (ch=" " or i = sLen) Then
token = Trim(Mid(s, start, i-start+1))
utoken = UCase(token)
If start = 1 Then
result = token
ElseIf (utoken = "AND" or utoken="OR" or utoken="NEAR") Then
result = result + " " + utoken
fSeparator = TRUE
Else
If fSeparator = FALSE Then
result = result + conjunction
End If
result = result + " " + token
fSeparator = FALSE
End If
start = i + 1
End If
Next
CreateSQLContai nsString = result
End Function


Nov 17 '05 #3

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

Similar topics

7
23877
by: mj | last post by:
Hello, thanks for the help. I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm firewall) Apache 2.0.52 MySQL 4.1.7 PHP 5.1.0-dev I have developed a PHP/MySQL web app that tracks jobs for me, and we
3
2204
by: francisl | last post by:
We have to build some script were I work to make a dynamic server inventory. But, the project team, a windows crew, start it all in vbscript and on mssql. Note, due to political reason, we can not use mysql or anyother one that are not *authorize*, it's oracle or mssql. Now we have to make it work also with our sun and HP unix server(plus one Linux). So I propose to use python, and after they see my litle python/wxwindow program, that...
3
11478
by: John MacIntyre | last post by:
Hi, Can anybody give me a hint as to how to convert a javascript array into a vbscript array? BTW-it only needs to work in IE5 & 6 Thanks in advance, John MacIntyre VC++ / VB / ASP / Database Developer
21
3986
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the data that is in this field can vary. It's a list of mechanical equipment, and how it is designated varies based on how the customer has them labeled. For example, a list of their equipment might look like: CH-1 CH-2 CH-3
2
362
by: AT | last post by:
I have the ASP page <%@ Language=VBScript %> <% Option Explicit Response.End A = b %>
3
2428
by: Mary | last post by:
Hi, Does anyone know of any software out there that would convert an application written in VBScript to either VB.NET or C#/C++ quite quickly for me, or will I have to re-write the application myself. Any help much appreciated.
5
1765
by: Martin Walke | last post by:
Hi all, Can someone help me out here? I'm been using ASP and VBScript for some years but have just ventured into the realms of using server side Javascript and apart from hitting various niggerly problems, this one baffles me. This is a very simplistic example of the problem. <%@ Language="JavaScript"%>
27
3249
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from tblB). The size of the db is about 200MBs. Now my issue is, the query has been running for over 3 hours already - I have no idea when it will end. I am using Access 2003. Are there ways to improve the speed performance? (Also, would the...
1
1766
by: Robert Neville | last post by:
Basically, I want to create a table in html, xml, or xslt; with any number of regular expressions; a script (Perl or Python) which reads each table row (regex and replacement); and performs the replacement on any file name, folder, or text file (e.g. css, php, html). For example, I often rename my mp3 (files); the folder holding the mp3 files; and replace these renamed values in a playlist/m3u/xml file. The table should hold clean...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
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...
0
8974
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
7500
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
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.