Results 1 to 10 of 27

Thread: "What’s in a String"- VBA break down Loop through character contents of a string

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10

    VBA break down Loop through character contents of a string Code Modifications

    A simple modification can be done to link "normal" characters so that simple text can be shown together rather than every individual character. This will make it easier to look along a long text containing a lot of "normal" text, such as words and numbers

    A simple text string can be added if the current and last character was something "normal" at code section
    Code:
            If Caracter Like "[A-Z]" Or Caracter Like "[0-9]" Or Caracter Like "[a-z]" Then ' Check for normal characters
                'SirNirios
                If Not Cnt = 1 Then ' I am only intersted in next line comparing the character before, and if i did not do this the next line would error if first character was a  "normal"  character
                    If Not Cnt = myLenf And (Mid(strIn, Cnt - 1, 1) Like "[A-Z]" Or Mid(strIn, Cnt - 1, 1) Like "[0-9]" Or Mid(strIn, Cnt - 1, 1) Like "[a-z]") Then  ' And (Mid(strIn, Cnt + 1, 1) Like "[A-Z]" Or Mid(strIn, Cnt + 1, 1) Like "[0-9]" Or Mid(strIn, Cnt + 1, 1) Like "[a-z]") Then
                     Let WotchaGot = WotchaGot & "|LinkTwoNormals|"
                    Else
                    End If
                Else
                End If
            Let WotchaGot = WotchaGot & """" & Caracter & """" & " & " ' This will give the sort of output that I need to write in a code line, so for example if I have a123 , this code line will be used 4 times and give like a final string for me to copy of   "a" & "1" & "2" & "3" &      I would phsically need to write in code  like  strVar = "a" & "1" & "2" & "3"   -  i could of course also write  = "a123"   but the point of this routine is to help me pick out each individual element
            Else ' Some other things that I would like to "see" normally - not "normal simple character" - or by a VBA constant, like vbCr vbLf  vbTab
    Any text can be used, but it should be chosen to be something unlikely to occur as text in your original string, strIn
    For a test code of like this …_
    Code:
    Sub TestWtchaGot()
    ' In the practice we would likely have our string obtained from some method and would have it held in some string variable
    Dim strTest As [color=blue]String[/color
     Let strTest = Chr(1) & "High""er" & vbCrLf & vbTab & """u."""
     Call WtchaGot(strIn:=strTest)
    End Sub
    _.. the seen text in the message box or Immediate window would be
    Chr(1) & "H" & |LinkTwoNormals|"i" & |LinkTwoNormals|"g" & |LinkTwoNormals|"h" & """" & "e" & |LinkTwoNormals|"r" & vbCr & vbLf & vbTab & """" & "u" & "." & """"
    Further down in the coding, the occurrences of " & |LinkTwoNormals|" can be removed with a simple line like
    Code:
         Let WotchaGot = Replace(WotchaGot, """ & |LinkTwoNormals|""", "", 1, -1, vbBinaryCompare)
    The output will then be like
    Chr(1) & "High" & """" & "er" & vbCr & vbLf & vbTab & """" & "u" & "." & """"

    Full modified coding including Calling routine for testing in the next post
    Last edited by DocAElstein; 02-27-2019 at 06:41 PM.

Similar Threads

  1. VBA Versions of my "Get Field" and "Get Reverse Field" formulas
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 4
    Last Post: 06-02-2017, 06:15 PM
  2. Get "Reversed" Field from Delimited Text String
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 3
    Last Post: 02-22-2015, 09:01 AM
  3. Replies: 1
    Last Post: 02-10-2015, 09:41 AM
  4. Replies: 4
    Last Post: 09-09-2013, 05:13 PM
  5. Ordinal Suffix (i.e., "st", "nd", "rd" and "th")
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 0
    Last Post: 03-20-2012, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •