Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

find strings without ascii characters in them

I am stripping out words in strings, in some cases I am left not with empty strings but with some spaces left.

How can I identify those?

finding spaces in strings wont work as strings with words naturally have spaces between them.

Its spaces in strings with no other characters

I am doing this as a function in vba
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

It isn't clear what your difficulty is. Once you have removed the words from a string, you could well be left with spaces. Are these a problem for you?
Perhaps we need a better understanding of your objective and/or an example.
Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

when the words are removed its leaving what appears to be empty strings but they are not, the strings are void of what we call words but none, one or more spaces are left.

I need to find those strings without exclusively searching for spaces as a string with words in it has spaces.

so how do i identify:

"  "
"   "

without pulling out "hello world "
if the string doesnt have any readable character, if i were to try verbalise this.
Replace "  " (two spaces) with " " (one space) and/or apply Trim() to the result strings.

/gustav
It depends on what is displaying the string as to whether a character is readable, but try this function:
Function StripASCIIControls(strMyString As String) As String
    StripASCIIControls = strMyString
    For i = 0 To 31
        StripASCIIControls = Replace(StripASCIIControls, Chr(i), "")
    Next i
End Function

Open in new window

it could have an unknown qty of spaces, in my first example it only has one space but could be many. I tried the function here but that doesnt work with the row i found which makes sense as it stops at chr31.

let me show long hand what i am doing:

I had  client strings that were for example:
"3 series BMW 316 SE"
"3 series BMW 316"

I have code that strips away elements so "3 series" gets removed as does the 3 digit model and marque. so leaves me with:
"SE" this is fine this is the trim level of the vehicle.
in the other case i end up with:

" "

what this means is my removal routines removed the words and leaves remnants being the spaces qty unknown. As far as the vehicle goes this is a base model with no trim so I want to identify this (as per the question) and I could add maybe the word "[no trim]" to the string if thats easier.

Hope you see now what I am doing now helps understand the wider scope.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Apologies sometimes its hard to verbalise the problem, works perfectly.
I am assuming it would work the same with multiple spaces in the string.
Yes, If there are only spaces left in the string, the Trim function will return a zero-length string.