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 實作有顯著差異時,才會需要這些函式和物件。

適用於