如何在 OpenEdge ABL / Progress 4GL 中将字符串转换为标题大小写?
如何在 OpenEdge ABL(又名 Progress 4GL)中将字符串转换为标题大小写?
我知道我可以使用 CAPS() 获得大写字母,使用 LC() 获得小写字母,但我找不到标题大小写(有时称为正确大小写)函数。
示例:
Input Output
------------ ------------
hello world! Hello World!
HELLO WORLD! Hello World!
How do I convert a string to title case in OpenEdge ABL (aka Progress 4GL)?
I know I can get upper case with CAPS(), and lower case with LC(), but I can't find the title case (sometimes called proper case) function.
Examples:
Input Output
------------ ------------
hello world! Hello World!
HELLO WORLD! Hello World!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为上述语句之一的顺序不正确 -
您将在字符串的开头添加一个额外的“”!还需要将 <= 更改为 <或者您将在返回字符串中添加一个额外的“”。
应该是:
至少我-认为-应该是这样...-
我
I think the order of one of those statements above is incorrect -
You'll be adding an extra " " at the beginning of the string! Also need to change the <= to < or you'll be tacking an extra " " into your return string.
It should be:
At least that's what I -think- it should be...
-Me
不久前我正在研究这个问题,除了类似于汤姆的解决方案之外,我还想出了两种变体。
我遇到的问题之一是并非所有单词都用空格分隔,例如运行时和读/写,因此我编写此版本以使用任何非字母字符作为分隔符。
我还想将变音符号和重音字符算作字母,所以它变得有点复杂。为了解决这个问题,我创建了两个版本的标题,一种大写,一种小写。如果两个字符串相同,则它是非字母字符,如果两个字符串不同,则它是字母字符。标题通常很短,因此这种方法并不像乍看起来那么低效。
另一个问题是标题大小写应该是特定于语言的,即动词和名词与介词和连词的处理方式不同。以下是标题大小写的一些可能规则:
be”)、副词(包括“than”和“when”)、形容词(包括
“这个”和“那个”)和代词(包括“它”)。
适当的形容词或单词具有同等的权重(交叉引用,
Microsoft 之前的软件、读/写访问、运行时)。小写
第二个词(如果是另一个词性或分词)
修改第一个词(操作方法、起飞)。
当然,如果不教授计算机英语,我就无法编写所有这些代码,因此我创建了这个版本作为一个简单但粗略的妥协;它在大多数情况下都有效,但也有例外。
我不得不提的是,汤姆的解决方案比我的解决方案快得多。根据您的需要,您可能会发现速度并不那么重要,因为您不太可能在大型数据处理过程或长字符串中使用它,但我不会忽略它。确保您的需求证明性能损失是合理的。
I was playing around with this a while back, and besides a solution similar to Tom's, I came up with two variations.
One of the problems I had was that not all words are separated by space, such as Run-Time and Read/Write, so I wrote this version to use any non-alphabetic characters as separators.
I also wanted to count diacritics and accented characters as alphabetic, so it became a little complicated. To solve the problem I create two versions of the title, one upper and one lower case. Where the two strings are the same, it's a non-alphabetic character, where they are different, it's alphabetical. Titles are usually very short, so this method is not as inefficient as might seem at first.
Another issue is that title case is supposed to be language specific, i.e. verbs and nouns are treated differently to prepositions and conjunctions. These are some possible rules for title case:
be"), adverbs (including "than" and "when"), adjectives (including
"this" and "that"), and pronouns (including "its").
proper adjective or the words have equal weight (Cross-Reference,
Pre-Microsoft Software, Read/Write Access, Run-Time). Lowercase the
second word if it is another part of speech or a participle
modifying the first word (How-to, Take-off).
I could of course not code all this without teaching the computer English, so I created this version as a simple if crude compromise; it works in most cases, but there are exceptions.
I have to mention that Tom's solution is very much faster than both of mine. Depending on what you need, you may find that the speed is not that important, since you're unlikely to use this in large data crunching processes or with long strings, but I wouldn't ignore it. Make sure that your needs justify the performance loss.