- Perl 6 Deep Dive
- Andrew Shitov
- 261字
- 2021-07-03 00:05:53
Converting register
There are many methods to change the register of the letters in a string. The first set contains simple lc and uc, which converts all characters to lower or upper case. Consider the following code snippet:
say 'String'.lc; # string
say 'String'.uc; # STRING
The other four methods are more complex.
The fc method converts a string to the so-called fold case. It is intended to be used in string comparisons. For example, compare the output of the three methods called on a string with the German letter ?, which is spelled as SS in uppercase, but is converted to ss in the fold-case. Consider the following code snippet:
say 'Hello, Stra?e!'.lc; # hello, stra?e!
say 'Hello, Stra?e!'.uc; # HELLO, STRASSE!
say 'Hello, Stra?e!'.fc; # hello, strasse!
(Keep in mind that, since June 2017, the German language officially has the upper version of ?, we can know about that right here https://en.wikipedia.org/wiki/Capital_%E1%BA%9E. The behavior of the methods may change.)
The tc method converts a string to the so-called title case, where the first letter of the string is capital.
say 'hey, you'.tc; # Hey, you
Notice that, if the string already contains uppercase letters, they will remain as is:
say 'dear Mr. Johnson'.tc; # Dear Mr. Johnson
Use the tclc method to convert all the other letters to lowercase:
say 'HI THERE!'.tclc; # Hi there!
The wordcase method capitalizes the first character of each word and makes the rest lowercase:
say 'hello WORLD'.wordcase; # Hello World
- 一步一步學(xué)Spring Boot 2:微服務(wù)項(xiàng)目實(shí)戰(zhàn)
- 移動(dòng)UI設(shè)計(jì)(微課版)
- Learning Real-time Processing with Spark Streaming
- PyTorch自然語(yǔ)言處理入門與實(shí)戰(zhàn)
- Visual C
- Python機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- jQuery炫酷應(yīng)用實(shí)例集錦
- Java Web開(kāi)發(fā)就該這樣學(xué)
- Learning Material Design
- JavaScript+jQuery網(wǎng)頁(yè)特效設(shè)計(jì)任務(wù)驅(qū)動(dòng)教程
- Apache Solr PHP Integration
- 精通Spring:Java Web開(kāi)發(fā)與Spring Boot高級(jí)功能
- Manage Your SAP Projects with SAP Activate
- Web前端開(kāi)發(fā)實(shí)戰(zhàn)教程(HTML5+CSS3+JavaScript)(微課版)
- Real-time Web Application Development using Vert.x 2.0