24. september 2002 - 21:23Der er
5 kommentarer og 1 løsning
Antal ord i tekst
Jeg har tidligere brugt denne følgende kode til at tælle antal ord i en tekst. Men nu er jeg i det problem at jeg skal tælle, hvor mange ord i en tekst der har over seks bogstaver. Nogen der hved hvordan man gør det?
Private Function WordCount(text As Variant) As Long
On Error Resume Next Dim counter As Long Dim words As Long Dim sum As Long Dim conmsg As String Const conbtns As Integer = vbOKOnly + vbInformation _ + vbDefaultButton1 + vbApplicationModal counter = 0 words = 0 sum = 0 text = Trim(text)
For counter = 1 To Len(text) If Asc(Mid(text, counter, 1)) > 32 Then If Err.Number <> 5 Then sum = sum + 1 Else Err.Clear End If End If
Next counter = 0 If sum > 0 Then For counter = 1 To Len(text) If counter + 1 > Len(text) Then words = words + 1 Else If Asc(Mid(text, counter, 1)) > 32 And _ Asc(Mid(text, counter + 1, 1)) = 13 Then words = words + 1 End If If Asc(Mid(text, counter, 1)) > 32 And _ Asc(Mid(text, counter + 1, 1)) = 32 Then words = words + 1 End If Err.Clear End If Next End If WordCount = words
tjaa... Det er også sådan noget jeg har tænkt på, men det er jo ikke særligt sikkert. Det kikser hvis der er "enter" to mellemtum eller tegn der ikke tælles med i ordet.
Function nChar(ByVal String) 'Legal_Char indeholder alle de tilladte karaktere Legal_Char = "@ ' . , _ - + 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Æ Ø Å Á É Í Ó Ú Ý Ä Ë Ï Ö Ü Â Ê Î Ô Û Ã Õ Ñ À Ò Ù"
String_Split = Split(String, " ") For x = LBound(String_Split) To UBound(String_Split) intCount = 1 New_String = "" For j = 0 To Len(String_Split(x)) Legal_Char_Split = Split(Legal_Char, " ") For i = LBound(Legal_Char_Split) To UBound(Legal_Char_Split) If LCase(Mid(String_Split(x), intCount, 1)) = LCase(Legal_Char_Split(i)) Then If New_String = "" Then New_String = Mid(String_Split(x), intCount, 1) Else New_String = New_String & Mid(String_Split(x), intCount, 1) End If End If Next intCount = intCount + 1 Next If nChar = "" Then nChar = New_String Else nChar = nChar & " " & New_String End If Next
End Function
For i = 1 to UBound(StringArray)
If Len(nChar(StringArray(i))) = 6 Then Count = Count + 1 End
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.