Last active
July 1, 2018 15:18
-
-
Save longtth/21bab15e693c41709fe1afbecde5d982 to your computer and use it in GitHub Desktop.
1 cái Extension Method để extend cái class String, vẫn chép từ SO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // You can use an extension method: | |
| public static class StringExtension | |
| { | |
| public static string GetLast(this string source, int tail_length) | |
| { | |
| if(tail_length >= source.Length) | |
| return source; | |
| return source.Substring(source.Length - tail_length); | |
| } | |
| } | |
| // And then call: | |
| string mystring = "34234234d124"; | |
| string res = mystring.GetLast(4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment