|
| |
| Navigation |
Synopsis Replace words in a string.
Description Suppose you are a book editor and want to ensure that all chapter
and section titles are properly capitalized. Here is how to do this.
Examples
module demo::common::WordReplacement import String; // capitalize: convert first letter of a word to uppercase public str capitalize(str word)We start by introducing a helper function capitalize ( ) that does the actual capitalization of a single word.
See Rascal:Patterns/Regular for details about regular expression patterns.
Next we give two versions of a capitalization functions for a sentence:
rascal>import demo::common::WordReplacement; ok rascal>capitalize("rascal"); str: "Rascal" rascal>capAll1("turn this into a capitalized title") str: "Turn This Into A Capitalized Title" rascal>capAll2("turn this into a capitalized title") str: "Turn This Into A Capitalized Title" |