Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Removes the specified string from the beginning of the target, if it exists
- /// </summary>
- /// <param name="target"></param>
- /// <param name="textToTrim"></param>
- /// <returns></returns>
- public static string TrimStringFromStart(string target, string textToTrim)
- {
- string result = target;
- while (result.StartsWith(textToTrim))
- {
- result = result.Substring(textToTrim.Length);
- }
- return result;
- }
- /// <summary>
- /// Removes the specified string from the end of the target, if it exists
- /// </summary>
- /// <param name="target"></param>
- /// <param name="textToTrim"></param>
- /// <returns></returns>
- public static string TrimStringFromEnd(string target, string textToTrim)
- {
- string result = target;
- while (result.EndsWith(textToTrim))
- {
- result = result.Substring(0, result.Length - textToTrim.Length);
- }
- return result;
- }
Add Comment
Please, Sign In to add comment