Home All Groups Group Topic Archive Search About

How do I do this with VB?



Author
14 Jul 2006 12:57 PM
the other john
I'm trying to extract the first 3 words (or 4 or whatever) from a
recordset field so I can format it with CSS.  I'm not sure how to do
this.  mid() won't work because there's no way to know how many
characters I'm dealing with.

In short I what to dynamically retrieve the first few words from a
field, format it with css, deliver it, then continue where it left off
without the css. 

Any suggestions?

Thanks!

Author
14 Jul 2006 1:10 PM
Mike Brind
the other john wrote:
> I'm trying to extract the first 3 words (or 4 or whatever) from a
> recordset field so I can format it with CSS.  I'm not sure how to do
> this.  mid() won't work because there's no way to know how many
> characters I'm dealing with.
>
> In short I what to dynamically retrieve the first few words from a
> field, format it with css, deliver it, then continue where it left off
> without the css.
>

Do you mean VBScript? Hope so...

<%
Dim str, i, spacepos, word
Response.Write "<strong>"
str = "My first three words in the sentence are bold"
for i = 1 to 3
spacepos = instr(str," ")
word = left(str,spacepos)
str = right(str,len(str)-spacepos)
response.write word
next
Response.Write "</strong>"
Response.Write str
%>

--
Mike Brind
Author
14 Jul 2006 1:32 PM
the other john
Yes, VBScript.

Assuming that there's no single function then to do this in ASP?

Thanks Mike, Cool!

Mike Brind wrote:
Show quote
> the other john wrote:
> > I'm trying to extract the first 3 words (or 4 or whatever) from a
> > recordset field so I can format it with CSS.  I'm not sure how to do
> > this.  mid() won't work because there's no way to know how many
> > characters I'm dealing with.
> >
> > In short I what to dynamically retrieve the first few words from a
> > field, format it with css, deliver it, then continue where it left off
> > without the css.
> >
>
> Do you mean VBScript? Hope so...
>
> <%
> Dim str, i, spacepos, word
> Response.Write "<strong>"
> str = "My first three words in the sentence are bold"
> for i = 1 to 3
> spacepos = instr(str," ")
> word = left(str,spacepos)
> str = right(str,len(str)-spacepos)
> response.write word
> next
> Response.Write "</strong>"
> Response.Write str
> %>
>
> --
> Mike Brind
Author
14 Jul 2006 2:44 PM
Bob Barrows [MVP]
You could use a regular expression. Somebody else will need to provide it if
you can't come up with one via google.

the other john wrote:
Show quote
> Yes, VBScript.
>
> Assuming that there's no single function then to do this in ASP?
>
> Thanks Mike, Cool!
>
> Mike Brind wrote:
>> the other john wrote:
>>> I'm trying to extract the first 3 words (or 4 or whatever) from a
>>> recordset field so I can format it with CSS.  I'm not sure how to do
>>> this.  mid() won't work because there's no way to know how many
>>> characters I'm dealing with.
>>>
>>> In short I what to dynamically retrieve the first few words from a
>>> field, format it with css, deliver it, then continue where it left
>>> off without the css.
>>>
>>
>> Do you mean VBScript? Hope so...
>>
>> <%
>> Dim str, i, spacepos, word
>> Response.Write "<strong>"
>> str = "My first three words in the sentence are bold"
>> for i = 1 to 3
>> spacepos = instr(str," ")
>> word = left(str,spacepos)
>> str = right(str,len(str)-spacepos)
>> response.write word
>> next
>> Response.Write "</strong>"
>> Response.Write str
>> %>
>>
>> --
>> Mike Brind

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Author
14 Jul 2006 7:17 PM
Anthony Jones
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:Ob076P1pGHA.524@TK2MSFTNGP05.phx.gbl...
> You could use a regular expression. Somebody else will need to provide it
if
> you can't come up with one via google.
>

It's a bit tricky.  This is the best I've come up with:-


Dim rgx: set rgx = new RegExp

rgx.Pattern = "((?:\b\w+\b.*?){3})(.*)?"

sHTML = rgx.Replace(rst("MyField").value, "<strong>$1</strong>$2"

It works when there are 3 or more words but fails when there are 0,1 or 2
words in the string.





Show quote
> the other john wrote:
> > Yes, VBScript.
> >
> > Assuming that there's no single function then to do this in ASP?
> >
> > Thanks Mike, Cool!
> >
> > Mike Brind wrote:
> >> the other john wrote:
> >>> I'm trying to extract the first 3 words (or 4 or whatever) from a
> >>> recordset field so I can format it with CSS.  I'm not sure how to do
> >>> this.  mid() won't work because there's no way to know how many
> >>> characters I'm dealing with.
> >>>
> >>> In short I what to dynamically retrieve the first few words from a
> >>> field, format it with css, deliver it, then continue where it left
> >>> off without the css.
> >>>
> >>
> >> Do you mean VBScript? Hope so...
> >>
> >> <%
> >> Dim str, i, spacepos, word
> >> Response.Write "<strong>"
> >> str = "My first three words in the sentence are bold"
> >> for i = 1 to 3
> >> spacepos = instr(str," ")
> >> word = left(str,spacepos)
> >> str = right(str,len(str)-spacepos)
> >> response.write word
> >> next
> >> Response.Write "</strong>"
> >> Response.Write str
> >> %>
> >>
> >> --
> >> Mike Brind
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>

AddThis Social Bookmark Button