Cyberdude
09-15-2005, 10:57 AM
I'm looking for a super simple technique for finding the first non-blank character in a string. I can do it with the following code:
Sub GetLoc()
Dim Strg As String, N As Integer, Loc As Integer
Strg = " ABC"
For N=1 To Len(Strg)
If Mid(Strg, N, 1) <> " " Then Exit For
Next N
Loc = N
End Sub
But this seems too "bulky". Surely there is a function that will do the job in one line ... something like InStr or Search. I thought that looking for the first occurrence of two characters, blank and a wildcard for nonblank, might be the key, but I can't seem to figure out what could represent a nonblank character. Any ideas? :banghead:
Sub GetLoc()
Dim Strg As String, N As Integer, Loc As Integer
Strg = " ABC"
For N=1 To Len(Strg)
If Mid(Strg, N, 1) <> " " Then Exit For
Next N
Loc = N
End Sub
But this seems too "bulky". Surely there is a function that will do the job in one line ... something like InStr or Search. I thought that looking for the first occurrence of two characters, blank and a wildcard for nonblank, might be the key, but I can't seem to figure out what could represent a nonblank character. Any ideas? :banghead: