Guest User

Untitled

a guest
Jan 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. /// <summary>
  2.         /// Removes the specified string from the beginning of the target, if it exists
  3.         /// </summary>
  4.         /// <param name="target"></param>
  5.         /// <param name="textToTrim"></param>
  6.         /// <returns></returns>
  7.         public static string TrimStringFromStart(string target, string textToTrim)
  8.         {
  9.             string result = target;
  10.             while (result.StartsWith(textToTrim))
  11.             {
  12.                 result = result.Substring(textToTrim.Length);
  13.             }
  14.  
  15.             return result;
  16.         }
  17.  
  18.         /// <summary>
  19.         /// Removes the specified string from the end of the target, if it exists
  20.         /// </summary>
  21.         /// <param name="target"></param>
  22.         /// <param name="textToTrim"></param>
  23.         /// <returns></returns>
  24.         public static string TrimStringFromEnd(string target, string textToTrim)
  25.         {
  26.             string result = target;
  27.             while (result.EndsWith(textToTrim))
  28.             {
  29.                 result = result.Substring(0, result.Length - textToTrim.Length);
  30.             }
  31.  
  32.             return result;
  33.         }
Add Comment
Please, Sign In to add comment