Count number of WORDS (Not character)

Results 1 to 2 of 2

Thread: Count number of WORDS (Not character)

  1. #1
    Join Date
    Dec 1969

    Default Count number of WORDS (Not character)

    Dear All,<BR><BR>Is there a possible way to count the number of words from a recordset field (text field)? I tried to do something similar as below:<BR><BR>For i = 1 to Len(lAdoRS.Fields("content"))<BR> if mid(lAdoRS.Fields("content"), i, 1) = " " Then<BR> space_count = space_count + 1<BR> end if<BR>Next<BR><BR>But since the "content" field is a text field, the Len(lAdoRS.Fields("content")) returns nothing (the paramater of Len is not a string...?)<BR><BR>What shall I do?

  2. #2
    Join Date
    Dec 1969

    Default RE: Count number of WORDS (Not character)

    Aside from being *VERY* inefficient, there is nothing wrong with your code, per se. Which leads me to believe that the record field you are getting doesn&#039t contain what you think it does.<BR><BR>Try this code and let us know what you see:<BR><BR>txt = lAdoRS.Fields("content")<BR>Response.Write "the &#039content&#039 field contains&#060;HR&#062;" & txt & "&#060;HR&#062;" & vbNewLine<BR>space_count = 0<BR>For i = 1 to Len(txt)<BR>&nbsp;&nbsp;&nbsp;&nbsp;If mid(txt, i, 1) = " " Then space_count = space_count + 1<BR>Next<BR>Response.Write "and the number of spaces is " & space_count & "&#060;P&#062;" & vbNewLine<BR><BR>*************************<BR><BR> Having said all that...<BR><BR>If you aren&#039t *too* fussy about the word count, you could simply do:<BR><BR>txt = lAdoRS.Fields("content")<BR>Response.Write "the &#039content&#039 field contains&#060;HR&#062;" & txt & "&#060;HR&#062;" & vbNewLine<BR>words = Split( txt )<BR>space_count = UBound( words ) + 1<BR><BR><BR>

Posting Permissions

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