...

View Full Version : How to improve this task



lebronletchev
02-14-2007, 01:48 PM
Dear friends,


If I have a database with 3 fields: thestring, str_start and str_finish. HOW
I DO to have the same results using "select statement" and " ubound function" ?




thestring="She was driving and drinking at the same time."
str_start="driving"
str_finish="driking"

response.write StringBreaker(thestring,str_start,str_finish) & "<br>"

thestring="He studies at UCM, but today he is unemployed"
str_start="studies"
str_finish="unemployed"

response.write StringBreaker(thestring,str_start,str_finish) & "<br>"
Thanks in advance

LeBRON LeTCHEV


Thank you for any suggestion

Lebron

Spudhead
02-14-2007, 05:03 PM
This sounds a bit like an assignment. It's not homework is it?

lebronletchev
02-14-2007, 05:55 PM
An assignment? No. I am older for doing assigments...

Lebron Letchev

itHighway
02-15-2007, 12:35 AM
Can you please give a few more details of what you require.

lebronletchev
02-15-2007, 10:37 AM
itHighway,

What I requiere has a name: generates substrings between 3 fields of a table.

Example:

INPUT

fields:

thestring str_start str_finish
"She was driving and drinking at the same time." "driving" "drinking"
"He studies at UCM, but today he is unemployed" "studies" "today"
"Snowstorm closes schools, snarls travel" "closes" "travel"
"2 Koreas agree to resume stalled talks" "agree" "resume"


OUTPUT
--------

RESPONSE.WRITE "driving and drinking"
RESPONSE.WRITE "studies at UCM, but today"
RESPONSE.WRITE "closes schools, snarls travel"
RESPONSE.WRITE "agree to resume"


Hard or easy?

I donīt know as generates substrings and I would be happy if I to have your helpul.

Thanks.

Lebron Letchev

Spudhead
02-15-2007, 04:04 PM
You can do this quite easily with a regular expression (http://www.devguru.com/technologies/vbscript/14108.asp):



function StringBreaker(thestring,str_start,str_finish)

dim oRegEx, oMatches, str_pattern, str_return
str_pattern = str_start & ".+" & str_finish

set oRegEx = New RegExp
oRegEx.Global = True
oRegEx.IgnoreCase = False
oRegEx.Pattern = str_pattern

set oMatches = oRegEx.Execute(thestring)
for each oMatch in oMatches
str_return = str_return & oMatch.value & "<br/>"
next
set oMatches = nothing

set oRegEx = nothing

StringBreaker = str_return

end function

response.write(StringBreaker("She was driving and drinking at the same time.","driving","drinking"))

lebronletchev
02-15-2007, 06:11 PM
Dear SpudHead,

Thank you.

Your "function StringBreaker" works fine when I input the data manually, how you make. However, when I try output from a table occurs problems. Sometimes it works fine, other no. WHY? Please, see the full script

My script:

<%


HERE YOUR FUNCTION



dim oconn
dim ors1, ors2
dim counter, matches
Server.ScriptTimeout = 5000000

set oconn=Server.CreateObject("ADODB.Connection")
oconn.Provider="Microsoft.Jet.OLEDB.4.0"

oconn.Open(Server.Mappath("db/testing.mdb"))
set ors1=Server.CreateObject("ADODB.recordset")

Dim strKeyword
'' strKeyword = split(Trim(Request.QueryString("look_for")), " ")
strKeyword = Request.QueryString("look_for")
%>

<%

oRs1.open "SELECT * FROM TAble2", oconn
do While not oRs1.eof

%>

<%

thestring=ors1("texts1")
strx_start=ors1("str_start")
strx_finish=ors1("str_finish")

response.write StringBreaker(thestring,strx_start,strx_finish) & "<br>"
%>

<%
oRs1.movenext
loop
oRs1.close
%>



Many thanks

LebronLetchev

Spudhead
02-16-2007, 10:49 AM
When you say "sometimes it works fine, others no", I have no idea what the problem actually IS. Does the page produce an error message? If so, what's the error message? If there's no error message, does the output not match what you were expecting? If it doesn't, what does it output and what were you expecting?

Three things, though:

1. This bit:
%>

<%

is pointless. Remove them.



2. The script i posted does nothing to validate the input that it gets. I suspect that the reason it's going wrong is that it's getting input that it's not expecting. Like an empty string, or something.

3. You've set your script to timeout after 5000000 seconds. This is a little over 8 weeks. If you have an ASP file that you expect to run continuously for 8 weeks, you need to rethink your application design.

lebronletchev
02-16-2007, 02:49 PM
Dear SpudHead,

It not works fine when I have the following case:

INPUT

fields:

thestring str_start str_finish

"She was driving and drinking "driving" "drinking"
although he was unemployed "unemployed" "same time"
but at the same time she win "win" "lottery"
the lkottery."



OUTPUT
--------

RESPONSE.WRITE "driving and drinking"


How I do to add the other substrings?
"unemployed" "same time"
"win" "lottery"


Thank you again

Lebron Letchev

Spudhead
02-16-2007, 05:16 PM
I'm sorry, I appreciate that English is not your native language but I couldn't understand what you just said.

Regarding this bit:


"She was driving and drinking "driving" "drinking"
although he was unemployed "unemployed" "same time"
but at the same time she win "win" "lottery"
the lkottery."

It would seem, to me, that this is three examples of input that you would pass to the function. But maybe you've mistyped it when posting. Can you confirm EXACTLY what you're passing in to the function in each of these cases?

The function should work as expected (at least, what I'm expecting) when called using:


response.write StringBreaker("She was driving and drinking", "driving", "drinking")

response.write StringBreaker("although he was unemployed but at the same time she", "unemployed", "same time")

response.write StringBreaker("but at the same time she win the lottery.", "win", "lottery")

lebronletchev
02-16-2007, 06:03 PM
Spudhead,

The phrase or string it is one:

response.write StringBreaker("She was driving and drinking although he was unemployed but at the same time she win the lottery","driving", "drinking")

response.write StringBreaker("She was driving and drinking although he was unemployed but at the same time she win the lottery","unemployed" "same time")

response.write StringBreaker("She was driving and drinking although he was unemployed but at the same time she win the lottery","win" "lottery")


I agree my English it is not too good! I am trying to say I donīt know as
I do for scanning all substrings. How I do for output the above StringBreaker()
using " Select" for output data froma table?

Thanks esp. for your patience!

Lebron letchev

Spudhead
02-19-2007, 10:45 AM
The code you posted above should work (with the commas put back in between the function arguments):


response.write StringBreaker("She was driving and drinking although he was unemployed but at the same time she win the lottery","driving", "drinking")

response.write StringBreaker("She was driving and drinking although he was unemployed but at the same time she win the lottery","unemployed", "same time")

response.write StringBreaker("She was driving and drinking although he was unemployed but at the same time she win the lottery","win", "lottery")

Does that not produce the output that you want?

I'm not sure what you mean by using it with output from a table? You just pass it in as you would anything else:


response.write(StringBreaker(myRecordset.Fields("big_long_sentence").value, str_start, str_finish))

lebronletchev
02-19-2007, 12:23 PM
Dear SpudHead,

Thank you for your efforts and spent time in helpme.

Now the script works fine. What I want to say by "Output of a table"?

<%

oRs1.open "SELECT * FROM TAble2", oconn
do While not oRs1.eof
response.write(StringBreaker(myRecordset.Fields("big_long_sentence").value, str_start, str_finish))
loop
%>

Thank you in advance. The script works fine (at least for some strings...)

Best

LeBronletchev



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum