need help

Results 1 to 8 of 8

Thread: need help

  1. #1
    Join Date
    Dec 1969

    Default need help

    Hi,<BR><BR>I&#039;m calling text to a page from a database. Is there an expression I can use so that only the first ten words appear, rather then the whole text.

  2. #2
    <eop> Guest

    Default R&D vbscript Left() function


  3. #3
    <eop> Guest

    Default I'm sorry... Right() function


  4. #4
    Mike Shaffer Guest

    Default RE: need help

    Well, since you want the first ten words (not a fixed number of characters) you will have to write a little function to do this. The way I would approach this is to scan for whitespace (e.g. space, tab, cr, lf, vtab, etc.) and punctuation (e.g. .,:;, etc.) using the INSTR function until you count to 10 occurrences OR run out of original string. Make sense?<BR><BR>Note: Some people might try to use SPLIT, but that would not take into account all of the possible word-separators mentioned above.

  5. #5
    ???? Guest

    Default ????


  6. #6
    !!! Guest

    Default !!!


  7. #7
    Eddie Campbell Guest

    Default RE: need help

    Assuming that your text is space delimited, this will do the trick.<BR>&#060;%<BR>MyVar = "There&#039;s a famous seaside town called Brighton, that&#039;s noted for fresh air and fun, and Mr and Mrs Ramsbotham went there with young Albert their son."<BR>NewString = ""<BR>WordCount = 0<BR>Do While WordCount &#060; 10 And Len(MyVar) &#062; 0<BR> SpacePos=Instr(MyVar," ")<BR> If SpacePos = 0 Then<BR> NewString = NewString & MyVar<BR> MyVar = ""<BR> Else<BR> NewString = NewString & Mid(MyVar,1,SpacePos)<BR> MyVar = Right(MyVar,Len(MyVar)-(SpacePos))<BR> End If<BR> WordCount = WordCount + 1<BR>Loop<BR>Response.Write WordCount NewString & "<BR>"<BR>%&#062;<BR>

  8. #8
    Mike Shaffer Guest

    Default RE: need help

    Eddie&#039;s solution is excellent. Keep in mind that it does not handle whitespace other than &#039;space&#039; (ASCII 32), nor does it handle multiple spaces in a row. Unfortunately, a very robust solution to what I described earlier would probably be overkill for what you want.<BR><BR>Here&#039;s another possibility. Instead of the first ten words, show the first x characters (say 50), with an ellipsis if the string was longer than 50 characters, e.g.<BR><BR>if len(rtrim(strData)) &#060; 50 then<BR> response.write rtrim(strData)<BR>else<BR> response.write left(rtrim(strData), 47) & "..."<BR>end if<BR><BR>Just a thought. ;-)

Posting Permissions

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