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
Printable View
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
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.
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
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
chr(9) is a tab
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