|
-
Oct 30th, 2000, 12:24 PM
#1
Thread Starter
Lively Member
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.
-
Oct 30th, 2000, 12:47 PM
#2
Fanatic Member
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.
-
Oct 30th, 2000, 01:45 PM
#3
Addicted Member
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...
-
Oct 30th, 2000, 02:24 PM
#4
Yep, i'm with vince on this one.
-
Oct 30th, 2000, 02:29 PM
#5
Hyperactive Member
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: 
-
Oct 30th, 2000, 03:42 PM
#6
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|