-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some collection and string helper functions
- Loading branch information
1 parent
66f40ce
commit 932fe8d
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,40 @@ | ||
namespace CsharpUtils | ||
using System; | ||
using System.Linq; | ||
|
||
namespace CsharpUtils | ||
{ | ||
public static class StringHelper | ||
{ | ||
#region Truncate | ||
|
||
public static string TruncateLastChars(this string source, int number) | ||
{ | ||
return source.Substring(0, source.Length - number); | ||
} | ||
|
||
public static string TruncateLastChar(this string source) | ||
{ | ||
return source.TruncateLastChars(1); | ||
} | ||
|
||
public static string TruncateEnding(this string source, string ending) | ||
{ | ||
if (!source.EndsWith(ending)) | ||
{ | ||
throw new InvalidOperationException(string.Format("'{0}' does not end with '{1}'", source, ending)); | ||
} | ||
return source.TruncateLastChars(ending.Length); | ||
} | ||
|
||
#endregion | ||
|
||
#region Ends with | ||
|
||
public static bool EndsWithOneOf(this string source, params string[] endings) | ||
{ | ||
return endings.Any(source.EndsWith); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains 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
This file contains 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