Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy How to improve this task

    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

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    This sounds a bit like an assignment. It's not homework is it?

  • #3
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    An assignment? No. I am older for doing assigments...

    Lebron Letchev

  • #4
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you please give a few more details of what you require.
    Sincerly,
    Zeeshan Ahmed
    CEO
    itHighway

  • #5
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    You can do this quite easily with a regular expression:

    Code:
    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"))

  • #7
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #8
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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.

  • #9
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #10
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    I'm sorry, I appreciate that English is not your native language but I couldn't understand what you just said.

    Regarding this bit:
    Code:
    "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:

    Code:
    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")

  • #11
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #12
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    The code you posted above should work (with the commas put back in between the function arguments):

    Code:
    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:

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

  • #13
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •