Results 1 to 3 of 3

Thread: [RESOLVED] Replicate and repeat a string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2009
    Posts
    106

    Resolved [RESOLVED] Replicate and repeat a string

    Hi all, i have string "super" May i know is there a function in vb where i can repeat the string like using the below code and return "supersupersuper" Thanks

    Code:
    StrDup(3, "super")

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Replicate and repeat a string

    here's a vb2008+ extension to the string class:

    vb Code:
    1. Module extensions
    2.     <System.Runtime.CompilerServices.Extension()> _
    3.     Public Function strDup(ByVal instance As String, ByVal number As Integer) As String
    4.         Dim returnString As String = ""
    5.         For x As Integer = 1 To number
    6.             returnString &= instance
    7.         Next
    8.         Return returnString
    9.     End Function
    10. End Module

    here's how to use it:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     MsgBox("super".strDup(3))
    3. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2009
    Posts
    106

    Re: Replicate and repeat a string

    Quote Originally Posted by .paul. View Post
    here's a vb2008+ extension to the string class:

    vb Code:
    1. Module extensions
    2.     <System.Runtime.CompilerServices.Extension()> _
    3.     Public Function strDup(ByVal instance As String, ByVal number As Integer) As String
    4.         Dim returnString As String = ""
    5.         For x As Integer = 1 To number
    6.             returnString &= instance
    7.         Next
    8.         Return returnString
    9.     End Function
    10. End Module

    here's how to use it:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     MsgBox("super".strDup(3))
    3. End Sub
    Thanks for helping

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