Monday, March 21, 2022

c# - How get last x chars from string by LINQ

One possibility (last 6 chars):
string s = "This is a text";
      
MessageBox.Show( s.Substring( s.Length - 6 ) );
Another possibility with LINQ support (last 6 chars):
string s = "This is a text";
      
MessageBox.Show( new string( s.TakeLast(6).ToArray() ) );

No comments:

Post a Comment