Results 1 to 6 of 6

Thread: string manipulation

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    string manipulation

    I am trying to transform

    (((p v q) > (r v (p v q))) > ((p & s) v (r v s))) > (p & r)

    into


    ~(~(~(p v q) v (r v (p v q))) v ((p & s) v (r v s))) v (p & r)

    So it seems that the algorithm should be:

    1. start with the left most character, go right, look for >, when the first > is found, go left and count the open and closed parentheses, when the open and closed parentheses equal each other then replace the open parentheses that eventually equaled the amount of closed parentheses with ~(
    2. then return to the first > found, then go right and look for another > and repeat the procedure until all > have been transformed.

    I used one of Rick's macros from another post to try to do it myself but I had problems with getting Excel to process ">" so I had to change the symbol to "t"

    I did eventually get it to work but then I realized that the required algorithm is more complicated since it can only handle one t per sentence.

    Code:
    Function matim(ByVal S As String) As String
      Dim X As Long, t As Long, Total As Long
      t = InStr(1, S, "t", vbTextCompare)
      
      For X = InStrRev(S, ")", t) To 1 Step -1
        If Mid(S, X, 1) = ")" Then
          Total = Total + 1
        ElseIf Mid(S, X, 1) = "(" Then
          Total = Total - 1
        End If
        If Total = 0 Then
          S = Application.Replace(S, X, 0, "~")
          Exit For
        End If
      Next
      S = Replace(S, "t", "v", , , vbTextCompare)
      matim = S
    End Function
    That code doesn't work.

    My final bit of string manipulation will then be to transform v into &

    This is done as follows:

    (p v q) = ~(~p & ~q)

    So the algorithm would go:

    1. Start at letter 1, go right, find the first v.
    2. Go right and look for either ( or a letter. Whichever one you find place a ~ to the left of it.
    3. Find either the first letter to the right or the first ( and put a ~ to the left of it.
    4. Then go left and find either the first letter or the first ).
    5. If one finds a letter place a ~ to the left of it.
    5a. Then continue left and place transform the next ( to ~(
    6. If one finds a ) then count it and continue left. As soon as the number of ) equals the number of (, then replace ( with ~(
    6a. Then continue left and it is always the case that the next character one finds is either ~ or (. If ~ do nothing and continue left and replace the first ( with ~(
    7. Return to the beginning of the newly transformed string and repeat steps one through 6.


    Input
    (~(~(~(p v q) v (r v (p v q))) v ((p & s) v (r v s))) v (p & r))

    1.
    (~(~(~~(~p & ~q) v (r v (p v q))) v ((p & s) v (r v s))) v (p & r))
    2.
    (~(~~(~~~(~p & ~q) & ~(r v (p v q))) v ((p & s) v (r v s))) v (p & r))
    3.
    (~(~~(~~~(~p & ~q) & ~~(~r & ~(p v q))) v ((p & s) v (r v s))) v (p & r))
    4.
    (~(~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) v ((p & s) v (r v s))) v (p & r))
    5.
    (~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~((p & s) v (r v s))) v (p & r))
    6.
    (~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~~(~(p & s) & ~(r v s))) v (p & r))
    7.
    (~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~~(~(p & s) & ~~(~r & ~s))) v (p & r))
    8.
    ~(~~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~~(~(p & s) & ~~(~r & ~s))) & ~(p & r))





    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg. 9h5lFRmix1R9h78GftO_iE
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h77HSGDH4A
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h76fafzcEJ
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h759YIjlaG
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h74pjGcbEq
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgzJJUDVv2Mb6YGkPYh4AaABAg. 9h5uPRbWIZl9h7165DZdjg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 10-02-2023 at 12:40 PM.

  2. #2
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    Quote Originally Posted by kylefoley76 View Post
    but then I realized that the required algorithm is more complicated since it can only handle one t per sentence.
    Check out the Split and Join. I haven't looked in detail at what you want to do with the portions of the string, but this snippet will give you an idea of how you might go about it:
    Code:
    Sub blah()
    zzz = "(((p v q) > (r v (p v q))) > ((p & s) v (r v s))) > (p & r)"
    yyy = Split(zzz, ">")
    For i = LBound(yyy) To UBound(yyy)
      yyy(i) = aFunctionToProcessTheSubString(yyy(i))
    Next i
    result = Join(yyy, " glug ")
    MsgBox result
    End Sub


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9iHOYYpaAbC
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgxuL6YCUckeUIh9hoh4AaABAg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwGTEyefOX7msIh1wZ4AaABAg. 9h4sd6Vs4qE9h7G-bVm8_-
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=Ugw3nF0C04AGt73H1BB4AaABAg. 9h6VhNCM-DZ9h7EqbG23kg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwGTEyefOX7msIh1wZ4AaABAg. 9h4sd6Vs4qE9h7KvJXmK8o
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=Ugw3nF0C04AGt73H1BB4AaABAg. 9h6VhNCM-DZ9h7E1gwg4Aq
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgywFtBEpkHDuK55r214AaABAg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg. 9h5lFRmix1R9h79hNGvJbu
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg. 9h5lFRmix1R9h79YAfa24T
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg. 9h5lFRmix1R9h79M1SYH1E
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg. 9h5lFRmix1R9h78SxhXTnR
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg. 9h5lFRmix1R9h78GftO_iE
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h77HSGDH4A
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h76fafzcEJ
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h759YIjlaG
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h74pjGcbEq
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgzJJUDVv2Mb6YGkPYh4AaABAg. 9h5uPRbWIZl9h7165DZdjg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 07-10-2023 at 07:08 PM.

  3. #3
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    I'd prefer you to tell us what's the aim of all this.
    I do not exclude the possibility there's a much simpler approach to it.



    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwplzlpYpmRqjGZem14AaABAg. 9hrvbYRwXvg9ht4b7z00X0
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgyOGlCElBSbfPIzerF4AaABAg. 9hrehNPPnBu9ht4us7TtPr
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwHjKXf3ELkU4u4j254AaABAg. 9hr503K8PDg9ht5mfLcgpR
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw1-OyZiDDxCHM2Rmp4AaABAg.9hqzs_MlQu-9ht5xNvQueN
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9htG01cKBzX
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htJ6TpIOXR
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwMKwGZpDjv7vi7pCx4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htOKs4jh3M
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxVW-am20rQ5GFuJ9F4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugygb0YiLOI7fG1zQSx4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugygb0YiLOI7fG1zQSx4AaABAg. 9htWqRrSIfP9i-fyT84gqd
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugygb0YiLOI7fG1zQSx4AaABAg. 9htWqRrSIfP9i-kIDl-3C9
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9i57J9GEOUB
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9i58MGeM8Lg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9i59prk5atY
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwaWs6XDXdQybNb8tZ4AaABAg. 9i5yTldIQBn9i7NB1gjyBk
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxV9eNHvztLfFBGsvZ4AaABAg. 9i5jEuidRs99i7NUtNNy1v
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugx2zSXUtmLBSDoNWph4AaABAg. 9i3IA0y4fqp9i7NySrZamd
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9i7Qs8kxEqH
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9i7TqGQYqTz
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAJSNws8Zz
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAJvZ6kmlx
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAK0g1dU7i
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKCDqNmnF
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKHVSTGHy
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKSBKPcJ6
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKgL6lrcT
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKlts8hKZ
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKrX7UPP0
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAL5MSjWpA
    Last edited by DocAElstein; 07-09-2023 at 07:48 PM.

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0
    Quote Originally Posted by snb View Post
    I'd prefer you to tell us what's the aim of all this.
    I do not exclude the possibility there's a much simpler approach to it.
    It's all about building software to solve logical problems. So in logic implication (p > q) is equal to (~p v q) and disjunction is equal to conjunction (p v q) = ~(~p & ~q). Even more difficult is equivalence: (p <-> q) = (p > q) & (q > p)

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0
    Quote Originally Posted by p45cal View Post
    Check out the Split and Join. I haven't looked in detail at what you want to do with the portions of the string, but this snippet will give you an idea of how you might go about it:
    Code:
    Sub blah()
    zzz = "(((p v q) > (r v (p v q))) > ((p & s) v (r v s))) > (p & r)"
    yyy = Split(zzz, ">")
    For i = LBound(yyy) To UBound(yyy)
      yyy(i) = aFunctionToProcessTheSubString(yyy(i))
    Next i
    result = Join(yyy, " glug ")
    MsgBox result
    End Sub
    It says there is a function not defined at this line of code:

    aFunctionToProcessTheSubString(yyy(i))

  6. #6

Similar Threads

  1. Reverse a string by using array method
    By hanishgautam in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 07-09-2013, 09:07 AM
  2. Extract Certain Characters From A Text String
    By bobkap in forum Excel Help
    Replies: 5
    Last Post: 05-24-2013, 06:25 AM
  3. Concatenate array string
    By tushar.tarafdar in forum Excel Help
    Replies: 2
    Last Post: 09-20-2012, 12:00 PM
  4. Find Color in the string using formula.
    By LalitPandey87 in forum Excel Help
    Replies: 4
    Last Post: 07-10-2012, 09:16 PM
  5. Find the First or Last So Many Words in a Text String
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 6
    Last Post: 06-21-2012, 09:42 PM

Posting Permissions

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