July 2013
Intermediate to advanced
370 pages
8h 27m
English
We already praised String’s execute method. In fact, it helped us create a Process object so we can execute system-level processes with only a couple of lines of code; see A Quick Look at the GDK.
We can get fancier with String using other methods. For example, take a look at the following code, which uses an overloaded operator of String:
| WorkingWithStrings/StringConvenience.groovy | |
| | str = "It's a rainy day in Seattle" |
| | println str |
| | |
| | str -= "rainy " |
| | println str |
The output shows the effect of the overloaded operator:
| | It's a rainy day in Seattle |
| | It's a day in Seattle |
The -= operator is useful for manipulating a string, it removes part of the left-side string that matches the string on the ...
Read now
Unlock full access