Strings.LSet(String, Int32) 方法

定義

傳回靠左對齊的字串,其中包含調整為指定之長度的指定字串。

C#
public static string LSet (string? Source, int Length);
C#
public static string LSet (string Source, int Length);

參數

Source
String

必要。 String 運算式。 字串變數的名稱。

Length
Int32

必要。 Integer 運算式。 傳回的字串長度。

傳回

靠左對齊的字串,其中包含調整為指定之長度的指定字串。

範例

這個範例示範如何使用 函 LSet 式。

VB
Dim testString As String = "Left"
Dim lString As String
' Returns "Left      "
lString = LSet(testString, 10)
' Returns "Le"
lString = LSet(testString, 2)
' Returns "Left"
lString = LSet(testString, 4)

備註

如果指定的字串長度超過指定的長度,則傳回的字串會縮短為指定的長度。 如果指定的字串比指定的長度短,則會將空格新增至傳回字串的右端,以產生適當的長度。

適用於

產品 版本
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另請參閱