2 /***************************************************************************
4 * Copyright (c) Raphaël Ernaelsten (@RaphErnaelsten) *
5 * All Rights Reserved. *
7 * NOTICE: Aura 2 is a commercial project. *
8 * All information contained herein is, and remains the property of *
9 * Raphaël Ernaelsten. *
10 * The intellectual and technical concepts contained herein are *
11 * proprietary to Raphaël Ernaelsten and are protected by copyright laws. *
12 * Dissemination of this information or reproduction of this material *
13 * is strictly forbidden. *
15 ***************************************************************************/
22 /// Static class containing extension for string type
24 public static class StringExtensions
27 /// Insert a string before all upper case letters
29 /// <param name="insertedString">String that will be inserted before the upper case letter</param>
30 /// <param name="ignoreFirstLetter">Should the first letter of the string be ignored? Default = true</param>
31 /// <param name="ignoreSpaces">Should insertion be ignored if a space is in front of the upper case letter? Default = true</param>
32 /// <returns>The modified string</returns>
33 public static string InsertStringBeforeUpperCaseLetters(this string sourceString, string insertedString, bool ignoreFirstLetter = true, bool ignoreSpaces = true)
35 if(string.IsNullOrEmpty(sourceString))
40 StringBuilder newText = new StringBuilder(sourceString.Length * 2);
43 newText.Append(sourceString[0]);
46 for(int i = 1; i < sourceString.Length; i++)
48 if(char.IsUpper(sourceString[i]) && (sourceString[i - 1] != ' ' || !ignoreSpaces))
50 newText.Append(insertedString);
52 newText.Append(sourceString[i]);
55 return newText.ToString();
59 /// Insert a char before all upper case letters
61 /// <param name="insertedCharacter">Char that will be inserted before the upper case letter</param>
62 /// <param name="ignoreFirstLetter">Should the first letter of the string be ignored? Default = true</param>
63 /// <param name="ignoreSpaces">Should insertion be ignored if a space is in front of the upper case letter? Default = true</param>
64 /// <returns>The modified string</returns>
65 public static string InsertCharacterBeforeUpperCaseLetters(this string sourceString, char insertedCharacter, bool ignoreFirstLetter = true, bool ignoreSpaces = true)
67 return sourceString.InsertStringBeforeUpperCaseLetters(insertedCharacter.ToString(), ignoreFirstLetter, ignoreSpaces);