- Comprehensive Ruby Programming
- Jordan Hudgens
- 140字
- 2021-07-02 21:13:26
String manipulation code examples
Let's start with an example. Let's say I want my application to always display the word Astros in capital letters. To do that, I simply write this:
"Astros".upcase
Now if I always want a string to be in lower case letters, I can use the downcase method, like this:
"Astros".downcase
These are the two methods I use quite often. However, there are other string methods available that we also have at our disposal.
For the rare times when you want to literally swap the case of the letters, you can leverage the swapcase method:
"Astros".swapcase
Lastly, if you want to reverse the order of the letters in the string we can call the reverse method:
"Astros".reverse
These methods are built into the String data class and we can call them on any string value in Ruby.
推薦閱讀
- Spring 5企業(yè)級(jí)開發(fā)實(shí)戰(zhàn)
- Python 深度學(xué)習(xí)
- Developing Middleware in Java EE 8
- Vue.js 3.x從入門到精通(視頻教學(xué)版)
- 數(shù)據(jù)結(jié)構(gòu)與算法JavaScript描述
- 信息安全技術(shù)
- 快速念咒:MySQL入門指南與進(jìn)階實(shí)戰(zhàn)
- SharePoint Development with the SharePoint Framework
- 表哥的Access入門:以Excel視角快速學(xué)習(xí)數(shù)據(jù)庫(kù)開發(fā)(第2版)
- Windows內(nèi)核編程
- 運(yùn)用后端技術(shù)處理業(yè)務(wù)邏輯(藍(lán)橋杯軟件大賽培訓(xùn)教材-Java方向)
- Spring Security Essentials
- Learning Node.js for .NET Developers
- Spring技術(shù)內(nèi)幕:深入解析Spring架構(gòu)與設(shè)計(jì)原理(第2版)
- 物聯(lián)網(wǎng)系統(tǒng)架構(gòu)設(shè)計(jì)與邊緣計(jì)算(原書第2版)