|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do I do this with VB?
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! the other john wrote:
> I'm trying to extract the first 3 words (or 4 or whatever) from a Do you mean VBScript? Hope so...> 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. > <% 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 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 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" "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message It's a bit tricky. This is the best I've come up with:-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. > 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 2words 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" > > |
|||||||||||||||||||||||