如何把握每个句子的第一个字母? [英] How to capitalize first letter of each sentence?

查看:145
本文介绍了如何把握每个句子的第一个字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何利用每个单词的第一个字母。但我想知道如何利用C#中的每个句子的第一个字母。

I know how to capitalize first letter in each word. But I want to know how to capitalize first letter of each sentence in C#.

推荐答案

这不一定是一个微不足道的问题。句子可以用许多不同的标点符号结束,而那些同样标点符号并不总是表示一个句子的末尾(如博士的缩写,因为有可能很多人可能对某个特定问题)。

This is not necessarily a trivial problem. Sentences can end with a number of different punctuation marks, and those same punctuation marks don't always denote the end of a sentence (abbreviations like Dr. may pose a particular problem because there are potentially many of them).

话虽这么说,你也许可以使用正则表达式寻找一个句子结尾的标点符号之后的话得到足够好的解决方案,但你必须添加不少特殊情况。这可能是更容易字来处理的字符或单词串字符。你仍然必须处理所有相同的特殊情况下,但它可能会比试图构建成一个正则表达式更容易。

That being said, you might be able to get a "good enough" solution by using regular expressions to look for words after a sentence-ending punctuation, but you would have to add quite a few special cases. It might be easier to process the string character by character or word by word. You would still have to handle all the same special cases, but it might be easier than trying to build that into a regex.

有很多奇怪的规则,语法和标点。你拿出任何可能的解决方案将不能够把他们都考虑在内。有些事情要考虑:(!?)

There are lots of weird rules for grammar and punctuation. Any solution you come up with probably won't be able to take them all into account. Some things to consider:


  • 句子可以用不同的标点符号结尾

  • 为此句子有些标点符号也可能在一个句子的中间使用(如​​缩写,如如先生博士)

  • 句子可以包含嵌套的句子。报价可能会带来一个特别的问题(例如他说,这是一个困难的问题!我不知道,他若有所思地说,如果它可以解决的。)

这篇关于如何把握每个句子的第一个字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆