Results 1 to 6 of 6

Thread: Replace

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    Dubuque, IA
    Posts
    134

    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.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Mess around with this:

    VB Code:
    1. Dim i As Integer, l As Integer
    2. i = 1
    3. Do
    4.   l = InStr(l, YourString, Chr(9))
    5.   i = i + 1
    6.   If i = 16 Then
    7.     MsgBox l
    8.   End If
    9.   If l = 0 Then Exit Do
    10. Loop

    You can use the Mid() function to replace it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I don't know if this is right, since I don't know what chr(9) is:

    VB Code:
    1. Private Sub Form_Load()
    2. Dim myString As String
    3. Dim i As Integer, l As Integer
    4.  
    5.   For i = 0 To 18
    6.     myString = myString & "v" & Chr(9) & "xas"
    7.   Next
    8.  
    9.   i = 1
    10.   l = 1
    11.   Do
    12.     l = InStr(l, myString, Chr(9))
    13.     i = i + 1
    14.     If i = 16 Then
    15.       myString = Mid(myString, 1, l) & "A" & Mid(myString, l + 1)
    16.       Exit Do
    17.     End If
    18.     If l = 0 Then Exit Do
    19.   Loop
    20.   MsgBox myString
    21. End Sub
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I replaced the chr(9)'s with A's and I believe this is right:

    VB Code:
    1. Private Sub Form_Load()
    2. Dim myString As String
    3. Dim i As Integer, l As Integer
    4.  
    5.   For i = 0 To 18
    6.     myString = myString & Chr(9) & "M"
    7.   Next
    8.  
    9.   i = 1
    10.   Do
    11.     l = InStr(l + 1, myString, Chr(9))
    12.     If l <> 0 Then
    13.       i = i + 1
    14.     End If
    15.     If i = 16 Then
    16.       myString = Mid(myString, 1, l + 1) & "0" & Mid(myString, l + 1)
    17.       Exit Do
    18.     End If
    19.     If l = 0 Then Exit Do
    20.   Loop
    21.   MsgBox myString
    22. End Sub
    Last edited by The Hobo; Mar 6th, 2002 at 05:09 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    Dubuque, IA
    Posts
    134
    chr(9) is a tab

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I made a function with this, try it:

    VB Code:
    1. Private Function ReplaceNum(Text As String, Place As Integer, Char As String, RWith As String) As String
    2. Dim myString As String
    3. Dim i As Integer, l As Integer
    4.  
    5.   myString = Text
    6.   i = 1
    7.   Do
    8.     l = InStr(l + 1, myString, Char)
    9.     If l <> 0 Then
    10.       i = i + 1
    11.     End If
    12.     If i = Place Then
    13.       myString = Mid(myString, 1, l + 1) & RWith & Mid(myString, l + 1)
    14.       Exit Do
    15.     End If
    16.     If l = 0 Then Exit Do
    17.   Loop
    18.   ReplaceNum = myString
    19. End Function
    My evil laugh has a squeak in it.

    kristopherwilson.com

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