[RESOLVED] Simple way to remove blank data from start of textbox?
I have an application where the user writes data into a textbox. The first line in the text should contain character Title information. When saving the file, I want to ensure that the beginning of the file contain character data, and not blanks, vbCrLf, etc. I want to remove all data(including vbCrLf, etc) until some valid character data occurs.
I started writing something and then hit the wall, so to speak. This seems to be more complicated than I thought it would be. Anybody have some ideas on how to identify what is non-character data?
Re: Simple way to remove blank data from start of textbox?
Have you tried to use Trim() function?
Re: Simple way to remove blank data from start of textbox?
Trim or LTrim() will delete blanks but not special chars.
There are many ways to do this, one is searching for the first char higher than 32 in the asccii code list, then removing all chars at left, example:
Code:
Private Function RemoveInvalidChars(ByRef pStr As String) As String
Dim i As Long, lLastInvalidChar As Long
If LenB(pStr) = 0 Then Exit Function
For i = 1 To Len(pStr)
If Asc(Mid(pStr, i, 1)) > 32 Then
lLastInvalidChar = i - 1
Exit For
End If
Next
RemoveInvalidChars = Right(pStr, Len(pStr) - lLastInvalidChar)
End Function
Usage:
Code:
Text1.Text = RemoveInvalidChars(Text1.Text)
Re: Simple way to remove blank data from start of textbox?
Hello. Thanks for the replies. The Trim function results in a string with Len > 0 and displays in debug mode as "". Very confusing to me.
JCIS-I think you've got it. That is exactly what I wanted to see. Thank you very much.
I have to assume that all language keyboards have no characters < 33(b).