Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String functions + search algorithm

Status
Not open for further replies.

JimFL

Programmer
Jun 17, 2005
131
GB
Hi,

Does anybody know how I would go about using asp vbscript functions to find the first occurrence of a word/s within a string. Then pull out the sentence that the string exists within. I have done some work with splitting strings up into arrays to find the item but am unsure of how I would get back to the start of the sentence after the item has been found - hence I dont think I am doing the most effective solution. Can anybody help with this?

For example

<%
dim str,search

str = "xxxxxxxxxxx.hello please help me to do this. this is tricky but Im sure it can be done efficiently. Thanks.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

search = "tricky"
%>


So I may try to look for the search string within the str, but would like to return

this is tricky but Im sure it can be done efficiently


Many thanks in advance

JimFl



 
In my example - using two full stops.

 
Dim i, j, k, sentence
i = inStr(1,str,search)
if i > 0 then
j = injStrRev(str,".",i)
k = inStr(i,str,".")
sentence = mid(str,j+1,k-j)
end if
 
What about an exclamation or question?!
Or an elipse ...
Is a parenthetical a separate sentece? (or a continuation of the preceding one?)

But, if you can eliminate all that and say that every sentence is separated by a single period "." you could achieve your goals using the functions InStr(), Mid(), and InStrRev().

If it gets more complicated than single periods you might consider using "Regular Expressions
 
Hi, Thanks for your responses..

As for the direct answer from dexeloper - I am getting an error

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'injStrRev'

line 4

Any ideas?

Sheco - thanks for your response, can you help with the above?


 
I think a typo!

j = injStrRev(str,".",i)


should be

j = inStrRev(str,".",i)

And the function works .

Thanks



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top