|
-
Mar 6th, 2002, 04:53 PM
#1
Thread Starter
Addicted Member
Replace
Whats the easiest way to replace the 16th occurence of chr(9) in a string with "" (Blank). Thanks in advance! Gene
chr(9) is a tab - i want to repace a tab in a tab delimited file
Last edited by Eugenious; Mar 6th, 2002 at 05:06 PM.
-
Mar 6th, 2002, 04:57 PM
#2
Stuck in the 80s
Mess around with this:
VB Code:
Dim i As Integer, l As Integer
i = 1
Do
l = InStr(l, YourString, Chr(9))
i = i + 1
If i = 16 Then
MsgBox l
End If
If l = 0 Then Exit Do
Loop
You can use the Mid() function to replace it.
-
Mar 6th, 2002, 05:01 PM
#3
Stuck in the 80s
I don't know if this is right, since I don't know what chr(9) is:
VB Code:
Private Sub Form_Load()
Dim myString As String
Dim i As Integer, l As Integer
For i = 0 To 18
myString = myString & "v" & Chr(9) & "xas"
Next
i = 1
l = 1
Do
l = InStr(l, myString, Chr(9))
i = i + 1
If i = 16 Then
myString = Mid(myString, 1, l) & "A" & Mid(myString, l + 1)
Exit Do
End If
If l = 0 Then Exit Do
Loop
MsgBox myString
End Sub
-
Mar 6th, 2002, 05:04 PM
#4
Stuck in the 80s
I replaced the chr(9)'s with A's and I believe this is right:
VB Code:
Private Sub Form_Load()
Dim myString As String
Dim i As Integer, l As Integer
For i = 0 To 18
myString = myString & Chr(9) & "M"
Next
i = 1
Do
l = InStr(l + 1, myString, Chr(9))
If l <> 0 Then
i = i + 1
End If
If i = 16 Then
myString = Mid(myString, 1, l + 1) & "0" & Mid(myString, l + 1)
Exit Do
End If
If l = 0 Then Exit Do
Loop
MsgBox myString
End Sub
Last edited by The Hobo; Mar 6th, 2002 at 05:09 PM.
-
Mar 6th, 2002, 05:04 PM
#5
Thread Starter
Addicted Member
-
Mar 6th, 2002, 05:07 PM
#6
Stuck in the 80s
I made a function with this, try it:
VB Code:
Private Function ReplaceNum(Text As String, Place As Integer, Char As String, RWith As String) As String
Dim myString As String
Dim i As Integer, l As Integer
myString = Text
i = 1
Do
l = InStr(l + 1, myString, Char)
If l <> 0 Then
i = i + 1
End If
If i = Place Then
myString = Mid(myString, 1, l + 1) & RWith & Mid(myString, l + 1)
Exit Do
End If
If l = 0 Then Exit Do
Loop
ReplaceNum = myString
End Function
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
|