FixedLengthString 建構函式

定義

初始化 FixedLengthString 類別的新執行個體。

多載

名稱 Description
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 屬性,否則無法宣告字串的固定長度。

使用此類別宣告固定長度字串,但不使用屬性。

Note

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

A 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 屬性,否則無法宣告字串的固定長度。

使用此類別宣告固定長度字串,但不使用屬性。

Note

Microsoft.VisualBasic.Compatibility.VB6 命名空間中的函式與物件,供工具從 Visual Basic 6.0 升級至 Visual Basic 2008 使用。 大多數情況下,這些函式和物件會重複你在 .NET Framework 中其他命名空間中能找到的功能。 只有當 Visual Basic 6.0 的程式碼模型與 .NET Framework 實作有顯著差異時,才需要使用這些工具。

適用於