Strings.Right(String, Int32) 方法

定義

傳回字串,其中包含從字串的右邊開始的指定數目的字元。

public:
 static System::String ^ Right(System::String ^ str, int Length);
public static string Right (string? str, int Length);
public static string Right (string str, int Length);
static member Right : string * int -> string
Public Function Right (str As String, Length As Integer) As String

參數

str
String

必要。 String 運算式,最右邊的字元會從此運算式中傳回。

Length
Int32

必要。 Integer. 數值運算式,表示要傳回的字元數。 如果為 0,則會傳回長度為零的字串 ("")。 如果大於或等於 str 中的字元數,則會傳回整個字串。

傳回

字串,其中包含從字串的右邊開始的指定數目的字元。

例外狀況

Length< 0.

範例

此範例示範如何使用 Right 函式傳回指定 String的子字串。 在具有 屬性的 Right 類別中,可能需要完整限定函 Right 式。

Dim testString As String = "Hello World!"
' Returns "World!".
Dim subString As String = Right(testString, 6)

備註

若要判斷 中的 str字元數,請使用 函 Len 式。 如果在 Windows Form 或任何其他具有 屬性的 Right 類別中使用,您必須使用 完整限定函 Microsoft.VisualBasic.Strings.Right式。

注意

舊版 Visual Basic 中的函 RightB 式會以位元組傳回字串,而不是字元。 其主要用於在雙位元組字元集 (DBCS) 應用程式中轉換字串。 所有目前的 Visual Basic 字串都位於 Unicode 中,不再 RightB 支援。

適用於

另請參閱