What happen to string.ToCommonSenseCase()?
https://softwareengineering.stackexchange.com/questions/387601
-
21-02-2021 - |
質問
I'm very confused about this. In most programming languages, there are string.ToUpperCase()
, string.ToLowerCase()
, sometimes Capitalize()
(which capitalize the first letter of the string), even ToTitleCase()
which capitalize every first letter of everyword.
But why isn't there any ToCommonSenseCase()
? The one that capitalize the first letter of each sentence? Why doesn't any language have it? I thought it should be the first utility function to implement case-wise.
解決
That's called sentence case, and there are some challenges with it:
- The word "I" needs to be capitalized, wherever it appears in the sentence. Granted, the programming language could detect that.
- Proper nouns ('names') always need to be capitalized. These are a lot harder to detect programmatically; a dictionary alone won't even help since "Mark" is both a name and a common word.
- A dot does not always signify the end of a sentence, e.g. when using abbreviations like this sentence does.
- Other languages than English have different capitalization rules: for example, German capitalizes all nouns.
You see that a proper sentence casing tool is much more complicated that just transforming each letter to capital or lowercase form; that's why standard libraries don't have this functionality.