Results 1 to 6 of 6

Thread: string manipulation

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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
  •