Udostępnij za pośrednictwem


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

Exception type

Error number

Condition

ArgumentException

5

Number is less than 0 or Character type is not valid.

ArgumentNullException

5

Character is Nothing.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

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 TestString As String
aObject = "This is a String contained within an Object" 
' Returns "PPPPP"
TestString = StrDup(5, "P")
' Returns "WWWWWWWWWW"
TestString = StrDup(10, aString)
' Returns "TTTTTT"
TestString = CStr(StrDup(6, aObject))

Requirements

Namespace:Microsoft.VisualBasic

**Module:**Strings

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

See Also

Reference

String Manipulation Summary

SPC Function

ArgumentException

ArgumentNullException