57 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Threading.Tasks;
 | |
| 
 | |
| namespace MontoyaTech.Rest.Net
 | |
| {
 | |
|     internal static class StringExtensions
 | |
|     {
 | |
|         public static int Count(this string input, char c)
 | |
|         {
 | |
|             int count = 0;
 | |
|             int len = input.Length;
 | |
|             for (int i = 0; i < len; i++)
 | |
|                 if (input[i] == c)
 | |
|                     count++;
 | |
| 
 | |
|             return count;
 | |
|         }
 | |
| 
 | |
|         public static string Separate(this IList<string> input, char separator)
 | |
|         {
 | |
|             if (input == null || input.Count == 0)
 | |
|                 return "";
 | |
|             else if (input.Count < 2)
 | |
|                 return input[0];
 | |
| 
 | |
|             var builder = new StringBuilder();
 | |
| 
 | |
|             builder.Append(input[0]);
 | |
| 
 | |
|             for (int i = 1; i < input.Count; i++)
 | |
|                 builder.Append(separator).Append(input[1]);
 | |
| 
 | |
|             return builder.ToString();
 | |
|         }
 | |
| 
 | |
|         public static string Separate(this IList<string> input, string separator)
 | |
|         {
 | |
|             if (input == null || input.Count == 0)
 | |
|                 return "";
 | |
|             else if (input.Count < 2)
 | |
|                 return input[0];
 | |
| 
 | |
|             var builder = new StringBuilder();
 | |
| 
 | |
|             builder.Append(input[0]);
 | |
| 
 | |
|             for (int i = 1; i < input.Count; i++)
 | |
|                 builder.Append(separator).Append(input[1]);
 | |
| 
 | |
|             return builder.ToString();
 | |
|         }
 | |
|     }
 | |
| }
 |