FixedLengthString 构造函数

定义

初始化 FixedLengthString 类的新实例。

重载

FixedLengthString(Int32)

通过指定长度来初始化 FixedLengthString 类的新实例。

FixedLengthString(Int32, String)

通过指定长度和初始值来初始化 FixedLengthString 类的新实例。

FixedLengthString(Int32)

通过指定长度来初始化 FixedLengthString 类的新实例。

public:
 FixedLengthString(int MaxChars);
public FixedLengthString (int MaxChars);
new Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString : int -> Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString
Public Sub New (MaxChars As Integer)

参数

MaxChars
Int32

一个 Integer,指定字符串的长度。

示例

以下示例演示如何声明和使用 FixedLengthString

Private Sub DemoFixedLengthString()  
    ' Declare a string that has a length of 7 characters.   
    Dim fixedString As New FixedLengthString(7)  
    ' Assign a value to the string.  
    fixedString.Value = "Hello World"  
    ' Display the string in a message box.  
    ' Note that only the first 7 characters are shown.  
    MsgBox(fixedString.ToString)  
End Sub  

注解

在 Visual Basic 6.0 中,可以在其声明中指定字符串的长度。 在 Visual Basic 中,除非在声明中使用 属性, VBFixedStringAttribute 否则无法将字符串声明为具有固定长度。

使用此类可以在不使用 特性的情况下声明固定长度的字符串。

注意

Microsoft.VisualBasic.Compatibility.VB6 命名空间中的函数和对象用于工具从 Visual Basic 6.0 升级到 Visual Basic 2008。 多数情况下,这些函数和对象可再现 .NET Framework 中其他命名空间的功能。 只有当 Visual Basic 6.0 代码模型与 .NET Framework 实现有显著区别时,才必须使用这些函数和对象。

适用于

FixedLengthString(Int32, String)

通过指定长度和初始值来初始化 FixedLengthString 类的新实例。

public:
 FixedLengthString(int MaxChars, System::String ^ InitialValue);
public FixedLengthString (int MaxChars, string InitialValue);
new Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString : int * string -> Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString
Public Sub New (MaxChars As Integer, InitialValue As String)

参数

MaxChars
Int32

一个 Integer,指定字符串的长度。

InitialValue
String

一个 String,指定初始内容。

示例

以下示例演示如何声明和使用 FixedLengthString

Private Sub DemoFixedLengthString()  
    ' Declare a string that has a length of 7 characters and assign the  
    ' initial string. The additional 5 positions will be padded with  
    ' spaces.  
    Dim fixedString As New FixedLengthString(7, "He")  
    ' Display the string in a message box.  
    MsgBox(fixedString.ToString)  
    ' Assign a new value to the string.  
    fixedString.Value = "Hello World"  
    ' Display again. Note that only the first 7 characters are shown.  
    MsgBox(fixedString.ToString)  
End Sub  

注解

在 Visual Basic 6.0 中,可以在其声明中指定字符串的长度。 在 Visual Basic 中,除非在声明中使用 属性, VBFixedStringAttribute 否则无法将字符串声明为具有固定长度。

使用此类可以声明固定长度的字符串,而不使用 属性。

注意

Microsoft.VisualBasic.Compatibility.VB6 命名空间中的函数和对象用于工具从 Visual Basic 6.0 升级到 Visual Basic 2008。 多数情况下,这些函数和对象可再现 .NET Framework 中其他命名空间的功能。 只有当 Visual Basic 6.0 代码模型与 .NET Framework 实现有显著区别时,才必须使用这些函数和对象。

适用于