Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Triming specific number of words before &
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Triming specific number of words before &

 Post Reply Post Reply Page  <123>
Author
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 11:37am

only thing is the snippet might start half way through a word, it would look better if you got x words before and after.

Yeah the thing I wrote should give you an idea of how to do it, but it is very buggy i didnt test it just wrote it in 5 mins

Back to Top
usaboy View Drop Down
Newbie
Newbie
Avatar

Joined: 05 July 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote usaboy Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 12:10pm

tanx ljamal... i did try to use that function but there were no result and i was getting the following error :

Technical Information (for support personnel)

  • Error Type:
    Microsoft VBScript runtime (0x800A01C2)
    Wrong number of arguments or invalid property assignment: 'inStrRev'
    /website4/SearchResults.asp, line 330
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 12:42pm
Change :
strString = left(strString, inStrRev(strString))

to
strString = left(strString, inStrRev(strString," "))
Back to Top
usaboy View Drop Down
Newbie
Newbie
Avatar

Joined: 05 July 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote usaboy Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 1:41pm

tanx ljamal... now i get the result page with no error.. but the problem is that there's nothing shown on the page.. just the ... trailing words before and after and the repeated region cols..

i guess somehow the whole string iss truncted!!! any idea/?

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 3:26pm


function FocusKeyword (strSting, strKeyword)
should be
function FocusKeyword (strString, strKeyword)

I wrote this function when I read your post, so I didn't check it.

Here I even tested it for you this time so it does work. I found that 100 returned a string too long for my liking so I changed 100 to 50...
see it in action
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 3:26pm
Just posting the completed function:
function FocusKeyword (strString, strKeyword)
     dim intPosition, intLength
     intLength = 50
     ' get keyword's position in the string
     intPosition = inStr(strString, strKeyword)

     'truncate characters before keyowrd to intLength
     if intPosition > intLength then
           strString = Right(strString, len(strString)-intLength)
           intPosition = inStr(strString, strKeyword)
     end if

     ' truncate characters after the beginning of the keyword to intLength
     if len(strString) > intPosition + intLength then
           strString = Left(strString, intPosition+intLength)
     end if

     'truncate to the first space in the string
     strString = right(strString, len(strString)-Instr(strString," "))

     'truncate to the first space and the end of the string
     strString = left(strString, inStrRev(strString," "))

     'highlight keyword
     strString = Replace(strString, strKeyword, "<b>"& strKeyword &"</b>")
     'return string
     FocusKeyword = strString
end function
Back to Top
usaboy View Drop Down
Newbie
Newbie
Avatar

Joined: 05 July 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote usaboy Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 4:20pm

tanx sooooo much ljamal... it did work for me too... but now the problem that i have is with multiple keywords search parameters... that this function works well with ONE keyword... but for more than ONE keyword it just shows few words... any idea what we can do about this???

once again i really appreciate your kind help and support.

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 4:54pm
The way the search engines deal with this is they find the first instance of any of the search terms (together or separate) and work from there. If there are other search terms near the first word, then they highlight all that appear.
I would use the split to separate the keywords into an array and determine which one appears first in the string. Then I would use that one to determine the length of the string and then highlight all the words in the array that appear in the new string. If I have time later, I'll work on it and post the function back to this thread.
Back to Top
 Post Reply Post Reply Page  <123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.