Strings.Right(String, Int32) 方法

定義

回傳包含指定字元數量的字串,從字串右側返回。

public:
 static System::String ^ Right(System::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形式或其他具有 Right 性質的類別,函數必須完全限定為 Microsoft.VisualBasic.Strings.Right

備註

早期版本中的 Visual BasicRightB 函式會回傳以位元組為單位的字串,而非字元。 其主要用於在雙位元組字元集 (DBCS) 應用程式中轉換字串。 目前所有Visual Basic字串皆為 Unicode,且不再支援 RightB

適用於

另請參閱