Capitalizing words in a string using c#

前端 未结 10 1334
攒了一身酷
攒了一身酷 2020-12-16 11:22

I need to take a string, and capitalize words in it. Certain words (\"in\", \"at\", etc.), are not capitalized and are changed to lower case if encountered. The first word s

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 11:59

    The easiest obvious solution (for English sentences) would be to:

    • "sentence".Split(" ") the sentence on space characters
    • Loop through each item
    • Capitalize the first letter of each item - item[i][0].ToUpper(),
    • Remerge back into a string joined on a space.
    • Repeat this process with "." and "," using that new string.

提交回复
热议问题