Results 1 to 4 of 4

Thread: replace : with _

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    replace : with _

    I have a text file with 3 colons (:) in each line (with text in between each colon)

    I need to replace the 3rd colon in each line with an underscore (_)

    how can I do this?

    thanks,

    Dimava
    Last edited by dimava; Mar 15th, 2003 at 08:23 PM.
    NXSupport - Your one-stop source for computer help

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Public Function ChangeThirdColon(strText As String) As String
    2.  
    3.     Dim intPos As Integer
    4.     Const COLON As String = ":"
    5.     Const UNDERSCORE As String = "_"
    6.    
    7.     intPos = InStr(1, strText, COLON)
    8.     intPos = InStr(intPos + 1, strText, COLON)
    9.     intPos = InStr(intPos + 1, strText, COLON)
    10.    
    11.     strText = Left$(strText, intPos - 1) & UNDERSCORE & Right$(strText, Len(strText) - intPos)
    12.  
    13. End Function

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    you da man
    NXSupport - Your one-stop source for computer help

  4. #4
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Should the third colon be the last colon of the line, InStrRev() will reduce 3 steps to find the indices to one. Modifying Martin's code : -
    VB Code:
    1. Public Function ChangeLastColon(strText As String) As String
    2.     Dim intPos As Integer
    3.     Const COLON As String = ":"
    4.     Const UNDERSCORE As String = "_"
    5.     intPos = InStrRev(strText, COLON, -1, vbBinaryCompare)
    6.     strText = Left$(strText, intPos - 1) & UNDERSCORE & Right$(strText, Len(strText) - intPos)
    7. End Function
    8.  
    9. Private Sub Command1_Click()
    10. Dim strVal As String
    11. strVal = "ABCD:EFGH:IJKL:MNOP"
    12. Call ChangeLastColon(strVal)
    13. MsgBox strVal
    14. End Sub
    Last edited by KayJay; Mar 16th, 2003 at 12:26 AM.

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

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