Sicherung

This commit is contained in:
maier_S
2022-03-24 15:52:02 +01:00
parent c9c8a7bcd0
commit bea46135fd
228 changed files with 75756 additions and 118 deletions

View File

@@ -0,0 +1,78 @@
using System;
using System.Text;
namespace FSI.Lib.CompareNetObjects
{
/// <summary>
/// Methods for manipulating strings
/// </summary>
public static class StringHelper
{
/// <summary>
/// Insert spaces into a string
/// </summary>
/// <example>
/// OrderDetails = Order Details
/// 10Net30 = 10 Net 30
/// FTPHost = FTP Host
/// </example>
/// <param name="input"></param>
/// <returns></returns>
public static string InsertSpaces(string input)
{
bool isLastUpper = true;
if (String.IsNullOrEmpty(input))
return string.Empty;
StringBuilder sb = new StringBuilder(input.Length + (input.Length / 2));
//Replace underline with spaces
input = input.Replace("_", " ");
input = input.Replace(" ", " ");
//Trim any spaces
input = input.Trim();
if (String.IsNullOrEmpty(input))
return string.Empty;
char[] chars = input.ToCharArray();
sb.Append(chars[0]);
for (int i = 1; i < chars.Length; i++)
{
bool isUpperOrNumberOrDash = (chars[i] >= 'A' && chars[i] <= 'Z') || (chars[i] >= '0' && chars[i] <= '9') || chars[i] == '-';
bool isNextCharLower = i < chars.Length - 1 && (chars[i + 1] >= 'a' && chars[i + 1] <= 'z');
bool isSpace = chars[i] == ' ';
bool isLower = (chars[i] >= 'a' && chars[i] <= 'z');
//There was a space already added
if (isSpace)
{
}
//Look for upper case characters that have lower case characters before
//Or upper case characters where the next character is lower
else if ((isUpperOrNumberOrDash && isLastUpper == false)
|| (isUpperOrNumberOrDash && isNextCharLower))
{
sb.Append(' ');
isLastUpper = true;
}
else if (isLower)
{
isLastUpper = false;
}
sb.Append(chars[i]);
}
//Replace double spaces
sb.Replace(" ", " ");
return sb.ToString();
}
}
}