Results 1 to 5 of 5

Thread: [RESOLVED] String Replacement ?

Threaded View

  1. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Location
    VietNam
    Posts
    81

    Re: String Replacement ?

    for simpler string such as strMyString = "Array(,,O,R,,)". i nearly did it with the following code just a little bit wrong logic somewhere in the first character however i think i will fine-tune it with no problem after a short sleep ( now i feel quite a lot more relax and happy with my effort so far ). if you guys have better solution just post it here for everyone reference.
    vb Code:
    1. Public Sub testcode()
    2.     Dim strMyString, strChar1, strChar2, strChar3, strChar4, strChar5, strChar6, strChar7, strChar8, strChar9, strChar10 As String
    3.     strMyString = "Array(,,O,R,,)" 'final result will look like this "Array("Oval","Rec")"
    4.    
    5.     strChar1 = Switch(Mid(strMyString, 7, 1) <> ",", Mid(strMyString, 7, 1), Mid(strMyString, 7, 1) = "," And _
    6.     Mid(strMyString, 6, 1) = "(", """")
    7.    
    8.     strChar2 = Switch(Mid(strMyString, 8, 1) <> ",", Mid(strMyString, 8, 1), Mid(strMyString, 8, 1) = "," And _
    9.     Mid(strMyString, 7, 1) = "(", """", Mid(strMyString, 8, 1) = "," And Mid(strMyString, 7, 1) = """", "", _
    10.     Mid(strMyString, 8, 1) = "," And Mid(strMyString, 7, 1) <> """" And Mid(strMyString, 7, 1) <> "(" And _
    11.     Mid(strMyString, 9, 1) <> ")" And Mid(strMyString, 9, 1) <> ",", """,""", Mid(strMyString, 8, 1) = "," And _
    12.     Mid(strMyString, 9, 1) = "," And Mid(strMyString, 7, 1) <> ",", "", Mid(strMyString, 8, 1) = "," And Mid(strMyString, 9, 1) = ")", """")
    13.    
    14.     strChar3 = Switch(Mid(strMyString, 9, 1) <> ",", Mid(strMyString, 9, 1), Mid(strMyString, 9, 1) = "," And _
    15.     Mid(strMyString, 8, 1) = "(", """", Mid(strMyString, 9, 1) = "," And Mid(strMyString, 8, 1) = """", "", _
    16.     Mid(strMyString, 9, 1) = "," And Mid(strMyString, 8, 1) <> """" And Mid(strMyString, 8, 1) <> "(" And _
    17.     Mid(strMyString, 10, 1) <> ")" And Mid(strMyString, 10, 1) <> ",", """,""", Mid(strMyString, 9, 1) = "," And _
    18.     Mid(strMyString, 10, 1) = "," And Mid(strMyString, 8, 1) <> ",", "", Mid(strMyString, 9, 1) = "," And Mid(strMyString, 10, 1) = ")", """")
    19.    
    20.     strChar4 = Switch(Mid(strMyString, 10, 1) <> ",", Mid(strMyString, 10, 1), Mid(strMyString, 10, 1) = "," And _
    21.     Mid(strMyString, 9, 1) = "(", """", Mid(strMyString, 10, 1) = "," And Mid(strMyString, 9, 1) = """", "", _
    22.     Mid(strMyString, 10, 1) = "," And Mid(strMyString, 9, 1) <> """" And Mid(strMyString, 9, 1) <> "(" And _
    23.     Mid(strMyString, 11, 1) <> ")" And Mid(strMyString, 11, 1) <> ",", """,""", Mid(strMyString, 10, 1) = "," And _
    24.     Mid(strMyString, 11, 1) = "," And Mid(strMyString, 9, 1) <> ",", "", Mid(strMyString, 10, 1) = "," And Mid(strMyString, 11, 1) = ")", """")
    25.    
    26.     strChar5 = Switch(Mid(strMyString, 11, 1) <> ",", Mid(strMyString, 11, 1), Mid(strMyString, 11, 1) = "," And _
    27.     Mid(strMyString, 10, 1) = "(", """", Mid(strMyString, 11, 1) = "," And Mid(strMyString, 10, 1) = """", "", _
    28.     Mid(strMyString, 11, 1) = "," And Mid(strMyString, 10, 1) <> """" And Mid(strMyString, 10, 1) <> "(" And _
    29.     Mid(strMyString, 13, 1) <> ")" And Mid(strMyString, 13, 1) <> ",", """,""", Mid(strMyString, 11, 1) = "," And _
    30.     Mid(strMyString, 13, 1) = "," And Mid(strMyString, 10, 1) <> ",", "", Mid(strMyString, 11, 1) = "," And Mid(strMyString, 13, 1) = ")", """")
    31.    
    32.     strChar6 = Switch(Mid(strMyString, 12, 1) <> ",", Mid(strMyString, 12, 1), Mid(strMyString, 12, 1) = "," And _
    33.     Mid(strMyString, 11, 1) = "(", """", Mid(strMyString, 12, 1) = "," And Mid(strMyString, 11, 1) = """", "", _
    34.     Mid(strMyString, 12, 1) = "," And Mid(strMyString, 11, 1) <> """" And Mid(strMyString, 11, 1) <> "(" And _
    35.     Mid(strMyString, 13, 1) <> ")" And Mid(strMyString, 13, 1) <> ",", """,""", Mid(strMyString, 12, 1) = "," And _
    36.     Mid(strMyString, 13, 1) = "," And Mid(strMyString, 11, 1) <> ",", "", Mid(strMyString, 12, 1) = "," And Mid(strMyString, 13, 1) = ")", """")
    37.    
    38.     strChar7 = Switch(Mid(strMyString, 13, 1) <> ",", Mid(strMyString, 13, 1), Mid(strMyString, 13, 1) = "," And _
    39.     Mid(strMyString, 12, 1) = "(", """", Mid(strMyString, 13, 1) = "," And Mid(strMyString, 12, 1) = """", "", _
    40.     Mid(strMyString, 13, 1) = "," And Mid(strMyString, 12, 1) <> """" And Mid(strMyString, 12, 1) <> "(" And _
    41.     Mid(strMyString, 14, 1) <> ")" And Mid(strMyString, 14, 1) <> ",", """,""", Mid(strMyString, 13, 1) = "," And _
    42.     Mid(strMyString, 14, 1) = "," And Mid(strMyString, 12, 1) <> ",", "", Mid(strMyString, 13, 1) = "," And Mid(strMyString, 14, 1) = ")", """")
    43.    
    44.     MsgBox "Array(" & strChar1 & strChar2 & strChar3 & strChar4 & strChar5 & strChar6 & strChar7 & ")"
    45. End Sub

    PS: as i said, the problems lie in the mark "," ( the comma ). the characters after it and before it and what happens after the first replacement occurs. i believe there must be some better ways beyond my knowledge at the time being and you guys the professionals can demonstrate it.if so do it please, it can be beautiful, thanks again
    Last edited by rocker123; May 21st, 2012 at 02:11 PM. Reason: PS

Posting Permissions

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



Click Here to Expand Forum to Full Width