| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- namespace qdr.app.studiou.orders2printpack.Extensions
- {
- public static class StringExt
- {
- public static string ToQuotedString(this string str)
- {
- if (str == null)
- return string.Empty;
- return ToDecoratedString(str, "\"");
- }
- public static string ToDecoratedString(this string str, string leftDecoration, string rightDecoration)
- {
- if (str == null)
- return string.Empty;
- return leftDecoration + str + rightDecoration;
- }
- public static string ToDecoratedString(this string str, string bothDecoration)
- {
- if (str == null)
- return string.Empty;
- return ToDecoratedString(str, bothDecoration, bothDecoration);
- }
- /// <summary>
- /// Returns a list of all duplicate string items in a collection.
- /// </summary>
- /// <param name="source">The source collection to check for duplicates.</param>
- /// <returns>An IEnumerable containing only the duplicate items.</returns>
- public static IEnumerable<string> GetDuplicates(this IEnumerable<string> source)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- return source
- .GroupBy(x => x)
- .Where(g => g.Count() > 1)
- .Select(g => g.Key);
- }
- }
- }
|