Permalink
Browse files
Add some String class level documentation with examples
- Loading branch information...
Showing
with
37 additions
and
0 deletions.
-
+37
−0
packages/builtin/string.pony
|
|
@@ -6,7 +6,44 @@ use @strtod[F64](nptr: Pointer[U8] box, endptr: USize) |
|
|
|
|
|
class val String is (Seq[U8] & Comparable[String box] & Stringable)
|
|
|
"""
|
|
|
A String is an ordered collection of characters.
|
|
|
|
|
|
Strings don't specify an encoding.
|
|
|
|
|
|
Example usage of some common String methods:
|
|
|
|
|
|
```pony
|
|
|
actor Main
|
|
|
new create(env: Env) =>
|
|
|
try
|
|
|
// construct a new string
|
|
|
let str = "Hello"
|
|
|
|
|
|
// make an uppercased version
|
|
|
let str_upper = str.upper()
|
|
|
// make a reversed version
|
|
|
let str_reversed = str.reverse()
|
|
|
|
|
|
// add " world" to the end of our original string
|
|
|
let str_new = str.add(" world")
|
|
|
|
|
|
// count occurrences of letter "l"
|
|
|
let count = str_new.count("l")
|
|
|
|
|
|
// find first occurrence of letter "w"
|
|
|
let first_w = str_new.find("w")
|
|
|
// find first occurrence of letter "d"
|
|
|
let first_d = str_new.find("d")
|
|
|
|
|
|
// get substring capturing "world"
|
|
|
let substr = str_new.substring(first_w, first_d+1)
|
|
|
// clone substring
|
|
|
let substr_clone = substr.clone()
|
|
|
|
|
|
// print our substr
|
|
|
env.out.print(consume substr)
|
|
|
end
|
|
|
```
|
|
|
"""
|
|
|
var _size: USize
|
|
|
var _alloc: USize
|
|
|
|
0 comments on commit
db0bc2c