Strings.Right(String, Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个字符串,该字符串包含字符串右侧的指定字符数。
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。