
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Last 2 Characters from String in C# Using Regex
Set the string −
string str = "Cookie and Session";
Use the following Regex to get the last 2 characters from string −
Regex.Match(str,@"(.{2})\s*$")
The following is the code −
Example
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*$")); } }
Output
on
Advertisements