Results 1 to 3 of 3

Thread: Replace char #5 by "-"

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    I have i lite serial number:
    1231728631652436125346152364124512653421543521374527145
    I want to put a - after each caracter..
    BUT I dont want that:
    12345-12345-12-----
    So the function must calculate the LEN an calculate how many - he must put...
    so ex:
    12345-12345-12345-12345-12345-23
    12353-31235-1325

    understand ??
    I hope ;0)

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    not replace, put between to 5 - 6 char and the 10 - 11 ......

  3. #3
    Guest
    A perfect case for recursion...

    Code:
    Public Function InsertDash(pInterval As Long, pText As String) As String
        Dim lstrTemp As String
        
        If Len(pText) <= pInterval Then
            InsertDash = pText
        Else
            lstrTemp = Left$(pText, pInterval)
            InsertDash = lstrTemp & "-" & InsertDash(pInterval, Mid$(pText, pInterval + 1, Len(pText) - (pInterval)))
        End If
    End Function
    Pass it the string and the interval (eg. 5) between dashes

    - gaffa

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