- 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.
推薦閱讀
- Python Network Programming Cookbook(Second Edition)
- Python數據可視化之Matplotlib與Pyecharts實戰
- HTML5+CSS3 Web前端開發技術(第2版)
- Mastering Linux Security and Hardening
- 詳解MATLAB圖形繪制技術
- Java程序設計案例教程
- Regression Analysis with Python
- 零代碼實戰:企業級應用搭建與案例詳解
- C指針原理揭秘:基于底層實現機制
- Android移動應用開發項目教程
- 數據結構:Python語言描述
- Java高手是怎樣煉成的:原理、方法與實踐
- SQL Server 2008實用教程(第3版)
- HTML5/CSS3/JavaScript技術大全
- 開源心法