How to Capitalize names

前端 未结 9 1821
余生分开走
余生分开走 2020-12-15 02:46

so basically if i want to transform a name from

stephen smith 

to

Stephen Smith

i can easily do it with c

9条回答
  •  甜味超标
    2020-12-15 03:24

    I use single line:

    string.Join(" ", str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Substring(0, 1).ToUpper() + c.Substring(1).ToLower()));
    

提交回复
热议问题