This documentation is archived and is not being maintained.

StrDup Function

Returns a string or object consisting of the specified character repeated the specified number of times.

Public Shared Function StrDup( _
   ByVal Number As Integer, _
   ByVal Character As { Char | String } _
) As String

-or-

Public Shared Function StrDup( _
   ByVal Number As Integer, _
   ByVal Character As Object _
) As Object

Parameters

Number
Required. Integer expression. The length to the string to be returned.
Character
Required. Any valid Char, String, or Object expression. Only the first character of the expression will be used. If Character is of type Object, it must contain either a Char or a String value.

Exceptions/Errors

Exception type Error number Condition
ArgumentException 5 Number < 0 or Character type is invalid.
ArgumentNullException 5 Character is Nothing.

Remarks

This function returns a String made up of repeated characters. The character that makes up the string is the first character in the Character argument, and it is duplicated Number number of times.

Example

This example uses the StrDup function to return a string of duplicated characters.

Dim aString As String = "Wow! What a string!"
Dim aObject As New Object()
Dim myString As String
aObject = "This is a String contained within an Object"
myString = StrDup(5, "P")   ' Returns "PPPPP"
myString = StrDup(10, aString)   ' Returns "WWWWWWWWWW"
myString = StrDup(6, aObject)   ' Returns "TTTTTT"

Requirements

Namespace: Microsoft.VisualBasic

Module: Strings

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

SPC Function | ArgumentException Class | ArgumentNullException Class

Show: