Compare Page Revisions
« Older Revision - Back to Page History - Newer Revision »
//-------------------------------------------------------------------------------------------------- public static string ToProperCase(this string text) { string result = ""; char apos = (char)39; for (int i = 0; i < text.Length; i++) { string s = text[i].ToString(); if (i == 0 || (!char.IsLetter(text[i - 1]) & text[i-1] != apos)) result += s.ToUpper(); else result += s; } return result; } //-------------------------------------------------------------------------------------------------- /// <summary> /// Takes a Proper-Cased variable name and adds a space before each /// capital letter. /// </summary> public static string AddSpaces(this string text) { string result = ""; for (int i = 0; i < text.Length; i++) { if (i > 0 && char.IsUpper(text[i])) result += " "; result += text.Substring(i, 1); } return result; }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.