C method of getting the last few digits of a string
- 2020-12-20 03:43:36
- OfStack
This article is an example of how C# gets the last few digits of a string. Share to everybody for everybody reference. Specific implementation methods are as follows:
#region Get the last few digits public string GetLastStr(string str,int num)
/// <summary>
/// Get the last few digits
/// </summary>
/// <param name="str"> The string to intercept </param>
/// <param name="num"> The specific number of digits returned </param>
/// <returns> The string that returns the result </returns>
public string GetLastStr(string str, int num)
{
int count = 0;
if (str.Length > num)
{
count = str.Length - num;
str = str.Substring(count, num);
}
return str;
}
#endregion
Hopefully this article has helped you with your C# programming.