Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

String Character Evaluation

I am trying to evaluate specific character entries in a string.  Is there a function to evaluate a character as alpha, numeric and other?

For instance I have the following lines of code where:

varWord = "Dr-10"
rstSList(2)= "Dr"

ElseIf InStr(varWord, rstSList(2)) Then
    lngPos = Len(rstSList(2))

What I need to do is evaluate the characters to the right of the "Dr" entry.  Part of the result needs to parse the varWord entry, but the rest needs to remove the non-alpha and non-numeric characters.  As a further example:

varWord = "Dr.-10"

How can I get the result?:

Result = "Dr 10"

I've done many string parsing routines B4, but not like this one.  Any help/suggestions would be appreciated.

  • 3
  • 2
  • 2
  • +2
1 Solution
You could use the Like operator. Are you trying to retrieve the characters to the right of the Dr or just find a match ?

varWord = "Dr?10"
If rstSList(2) Like varWord Then
if IsNumeric(Field) then...
if isDate(field) then...
Try this function :

Function StripChars(ByVal strEntryString As String, ByVal strRemoveCharacters As String) As String

    On Error GoTo StripChars_Err
    Dim intCount As Integer
    Dim strReplaceChar As String
    Dim strTemp As String
    strTemp = strEntryString
    ' Loop through all chars in RemoveCharacters string (All chars that need to be removed)
    If strRemoveCharacters > "" Then
        For intCount = 1 To Len(strRemoveCharacters)
            strReplaceChar = Mid(strRemoveCharacters, intCount, 1)
            strTemp = Replace(strTemp, strReplaceChar, "")
    End If
    StripChars = strTemp
    Exit Function
    MsgBox Error, vbExclamation
    Resume StripChars_Exit
End Function

Pass the string and the characters to be removed, and it will strip them from the string, E.g.




Does this help?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Opps, the question did not soak in.  Sorry for the erroneous response
When calling the function you should pass Mid(varWord,3). I forgot to mention that
It sounds like an InputMask may be the easier option for you. Also Access 2000 and later has a built in function called Replace() that allows you to replace character(s) within a string with other character(s) or an empty string.

Cheers, Andrew
rknowledgeAuthor Commented:
Thanks for some of the comments.  Unfortunately these will not work for me in this case.  Let me expain a bit more.

My program has data stored on Quality Control checks for installation work done at homes and businesses.  The key field I am looking to work w/ is the address.

I already have written the address entry check that meets all the standards for a proper address as far as the first word being numeric and the second if (ie. North will transform to "N") and Drive can only be entered as DR.

All of the inspection techs use digital cameras for pictures of various aspects of the work.  They rename these pictures and store them in a folder on the network.  I have chosen to use an image field on a form to actually view the pictures and depending on the current selected record a list of the associated pictures are populated in a list box.  From here you can choose which picture to view and the image will link to the file with the same address(it's a very stringent lookup).

The problem comes in where the QC techs name their picture outside of any kind of interface where I control their entry.  I am trying to check all archived pictures and rename automatically or manually to meet the standards.

If I have the address:

123 N Elm St     in the database the pic file name may look like:

123 N. Elm St., GBB (2022).jpg

There is no telling what characters they may use.  If I could distinguish alpha characters directly my problem is solved.  Would I need to build a list of alpha characters and parse the string that way or is there some handy-dandy function?

Something like this:

Function StripAlpha(strIn As String) As String
Dim strOut As String
Dim I As Long

For I=1 To Len(strIn)
   If Instr("abcdefghijklmnopqrstuvwxyz ",Mid$(strIn,I,1))<>0 Then strOut = strOut & Mid$(strIn,I,1)
StripAlpha = strOut
End Function

You can use this to retrieve the alpha characters in a string which you can then use a Like operator to match. If you need other characters, just add them to the abcdef...etc bit.
rknowledgeAuthor Commented:
You know what, that's would work.  I was thinking of something more complex.  Sometimes it helps to ask questions.

Thanks, there's some more to it but I know that's on the right track.

Anyway I did work out another solution.  I was able to leave the end of the filename string so I did this instead.

ElseIf varWord = rstSList(1) Or _
    InStr(varWord, rstSList(1)) Then
        If IsNumeric(Right(varWord, 1)) Then
            If IsNumeric(Right(varWord, 2)) Then
                varWord = Left(varWord, Len(varWord) - 2)
            End If
            varWord = Left(varWord, Len(varWord) - 1)
        End If
        strNewAddress = ReplaceStr(strFName, varWord, rstSList(2), 2)
        blnFound = True
        GoTo SListFound

Thanks, hope it helps you out!

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now