Đặt chuỗi -
string str = "Cookie and Session";
Sử dụng Regex sau để lấy 2 ký tự cuối cùng từ chuỗi -
Regex.Match(str,@"(.{2})\s*$") Sau đây là mã -
Ví dụ
using System;
using System.Text.RegularExpressions;
public class Demo {
public static void Main() {
string str = "Cookie and Session";
Console.WriteLine(Regex.Match(str,@"(.{2})\s*$"));
}
} Đầu ra
on