c# 學習筆記 - 將英文字串中,每個單字第一個字母變大寫
將一串英文字,每個單字第一個字母轉換成大寫 using System; using System.Collections.Generic; using System.Web; /// <summary> /// Summary description for Tools /// </summary> public class Tools { public Tools() { // // TODO: Add constructor logic here // } public static string UppercaseWords(string value) { char[] array = value.ToCharArray(); // Handle the first letter in the string. if (array.Length >= 1) { if (char.IsLower(array[0])) { array[0] = char.ToUpper(array[0]); } } // Scan through the letters, checking for spaces. // ... Uppercase the lowercase letters following spaces. for (int i = 1; i < array.Length; i++) { if (array[i - 1] == ' ') { if (char.IsLower(array[i])) { array[i] = char.ToUpper(array[i]); }