How to count number of characters in RTF except crlf and spaces? (in two ways)
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 'Controls - How to count number of characters in RTF except crlf and spaces? (in two ways) 'Method 1: Private Sub Command1_Click() MsgBox "Total Chars: " & Len(RichTextBox1.Text) & vbCrLf & _ "Chars, No CRLFs: " & Len(Replace(RichTextBox1.Text, vbCrLf, "")) & vbCrLf & _ "Chars, NO CRLFs, No Spaces: " & Len(Replace(Replace(RichTextBox1.Text, vbCrLf, ""), _ " ", "")) End Sub 'Method 2: 'To Calculate the Number of Characters excluding CRLFs (using API): Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const EM_GETLINECOUNT = &HBA Private Sub Command1_Click() MsgBox "Chars, Excluding CRLF: " & Len(RichTextBox1.Text) - _ (2 * (SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0) - 1)) End Sub |