2009-07-22 74 views

回答

31
string name = "HECHT, WILLIAM"; 
string s = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()); 

(注意它只能降低到上層,因此開始小寫)

+0

那裏有那個東西嗎?天啊。 +1 – 2009-07-22 21:33:09

+0

@Marc:'ToTitleCase()'正確地處理「Peter O'Toole」和「Mary Jones-Smith」嗎? – 2009-07-22 21:35:08

0
public static string CamelCase(this string s) 
    { 
     if (String.IsNullOrEmpty(s)) 
      s = ""; 
     string phrase = ""; 
     string[] words = s.Split(' '); 
     foreach (string word in words) 
     { 
      if (word.Length > 1) 
       phrase += word.Substring(0, 1).ToUpper() + word.Substring(1).ToLower() + " "; 
      else 
       phrase += word.ToUpper() + " "; 

     } 
     return phrase.Trim(); 
    } 
0

我投馬克的回答,但是這也將工作:

string s = Microsoft.VisualBasic.Strings.StrConv("HECHT, WILLIAM", VbStrConv.ProperCase,0); 

您需要添加適當的引用,但我確定它可以在全部較高的輸入上運行。

相關問題