Results 1 to 6 of 6

Thread: Removing Quotes from strings in an array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96

    Angry

    Hi,

    Can anyone help me with the problem.

    I have an array of strings e.g. strErrors()
    If any of the strings held in this array hold ' or " I want to replace it with a space.

    I read in the data from log files (up to 100) using FileSystemObject and readline.

    I've tried everything I know to try and replace the chars but nothing seems to work.

    Any help is greatfully appreciated.

    H.

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Code:
    'For VB6
    theString = Replace(theString, Chr(39), Chr(32))
    theString = Replace(theString, Chr(34), Chr(32))
    
    'For versions without the Replace() function
    For X = 1 to Len(theString)
        intASCII = Asc(Mid(theString, X, 1)
        If intASCII = 34 or intASCII = 39 then
            newString = newString & Chr(32)
            Else
            newString = newString & Chr(intASCII)
        End If
    Next X
    I haven't verified this, so I hope it works for ya.
    -Excalibur

  3. #3
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Outch !

    Be carfull with this parsing function...

    I would have used the "Instr" function because you dont have to parse the entire string if there is only a couple caracters to replace...

    Just another good solution...

  4. #4
    Guest
    Yep, i'm with vince on this one.

  5. #5
    Hyperactive Member D12Bit's Avatar
    Join Date
    Oct 2000
    Location
    Guatemala
    Posts
    373

    Lightbulb Can you made it short?

    Take a look at this...

    Code:
    Option Explicit
    Dim MyText$, Mytext2$, PosX%, Here%
    
    Private Sub Command1_Click()
    PosX = 1
    Here = 0
    MyText = Text1
    Text3 = Len(Text1)
    Mytext2 = ""
    Do
        DoEvents
        Here = InStr(PosX, MyText, Chr(34))
        If Here > PosX Then
            Mytext2 = Mytext2 & Mid(MyText, PosX, Here - PosX) & " "
        ElseIf Here = PosX Then
            Mytext2 = Mytext2 & " "
        Else
            Mytext2 = Mytext2 & Mid(MyText, PosX)
            Exit Do
        End If
        PosX = Here + 1
    Loop Until Here = 0
    
    PosX = 1
    Here = 0
    
    Do
        DoEvents
        Here = InStr(PosX, Mytext2, Chr(39))
        If Here > PosX Then
            Text2 = Text2 & Mid(Mytext2, PosX, Here - PosX) & " "
        ElseIf Here = PosX Then
            Text2 = Text2 & " "
        Else
            Text2 = Text2 & Mid(Mytext2, PosX)
            Exit Do
        End If
        PosX = Here + 1
    Loop Until Here = 0
    Text4 = Len(Text2)
    End Sub
    Using Instr() i quickly made this but it seems very long,
    can any one please made short

    Saludos...
    "Who Dares Wins" - "Quien se Arriesga Gana"
    Mail me at:

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Yeah, it was rather hurried

    Code:
    newString = theString
    tStart = InStr(1, newString, Chr(39))
    qStart = InStr(1, newString, Chr(34))
    
    Do While tStart > 0
        newString = Left(newString, tStart - 1) & " " & Mid(newString, tStart + 1)
        tStart = InStr(1, newString, Chr(39))
    Loop
    
    Do While qStart > 0
        newString = Left(newString, qStart - 1) & " " & Mid(newString, qStart + 1)
        qStart = InStr(1, newString, Chr(34))
    Loop
    
    theString = newString
    This might be a bit faster heh and a bit more safe. You could just put theString all the way through, I just have a thing about temp variables to hold data being worked on.
    -Excalibur

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