Results 1 to 3 of 3

Thread: [Resolved] Insert Space Every X Character

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    [Resolved] Insert Space Every X Character

    Hello, I've been racking my brain out trying to figure out how to do this!

    What i want to do is Insert a space every X character so like if i wanted a space every 3 characters...

    "HelloEveryoneHowAreYouGoing?I'mFine!"
    to
    "Hel loE ver yon eHo wAr eYo Goi Ng? I'm Fin e!"

    Some of the problems that i have is when i insert a space the length of the string changes and i need to count four instead of 3 for the changed bit. Also with the maths, does it effect it if the string length doesn't divide by 3 completely (such as above)?

    Can you please help me come up with this code!
    Last edited by Slyke; May 17th, 2006 at 01:11 AM.

  2. #2
    New Member
    Join Date
    May 2006
    Posts
    9

    Re: Insert Space Every X Character

    VB Code:
    1. Function StringSpace()
    2.  
    3. Dim aString As String
    4.  aString = "HelloEveryoneHowAreYouGoing?I'mFine!"
    5.  
    6. Dim output As String
    7.  output = ""
    8.  
    9.  
    10. For i = 1 To Len(aString)
    11.  
    12.     output = output & Mid(aString, i, 1)
    13.    
    14.     If (i Mod 3 = 0) Then
    15.         output = output & " "
    16.     End If
    17. Next
    18.  
    19. MsgBox output
    20.  
    21. End Function

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Insert Space Every X Character

    Thank You!

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