-
Does anybody know how to count number of characters in RTF? I used a Len function but it counts every character (when I hit enter it counts it as 2 chars). I want just the number of chars with and without spaces.
Thanks in advance
------------------
Visual Basic Programmer (at least I want to be one)
-----------------
PolComSoft
You will hear a lot about it.
-
If you have VB6.0 you have the Ever Handy Replace Function which you can use, eg.
Code:
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
Otherwise you can use the SendMessage API with the EM_GETLINECOUNT Message to Calculate the Number of Characters excluding CRLFs, eg.
Code:
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
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Unfortunately I don't have VB6 but the second function seems to work. Thanks Aaron.
------------------
Visual Basic Programmer (at least I want to be one)
-----------------
PolComSoft
You will hear a lot about it.