[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

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
0
PeterBaileyUk
Asked:
PeterBaileyUk
  • 5
  • 4
1 Solution
 
GrahamSkanCommented:
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.
0
 
PeterBaileyUkAuthor Commented:
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 "
0
 
PeterBaileyUkAuthor Commented:
if the string doesnt have any readable character, if i were to try verbalise this.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
Gustav BrockCIOCommented:
Replace "  " (two spaces) with " " (one space) and/or apply Trim() to the result strings.

/gustav
0
 
GrahamSkanCommented:
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

0
 
PeterBaileyUkAuthor Commented:
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.
0
 
GrahamSkanCommented:
That is a bit clearer. How about?
Function IsBaseModel(strMyString As String) As Boolean
    If Len(Trim(strMyString)) = 0 Then
        IsBaseModel = True
    End If
End Function

Open in new window

0
 
PeterBaileyUkAuthor Commented:
Apologies sometimes its hard to verbalise the problem, works perfectly.
0
 
PeterBaileyUkAuthor Commented:
I am assuming it would work the same with multiple spaces in the string.
0
 
GrahamSkanCommented:
Yes, If there are only spaces left in the string, the Trim function will return a zero-length string.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now