We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 32e96aa + 34e5c24 commit ef089ffCopy full SHA for ef089ff
src/doc/trpl/strings.md
@@ -117,6 +117,30 @@ let dog = hachiko.chars().nth(1); // kinda like hachiko[1]
117
118
This emphasizes that we have to go through the whole list of `chars`.
119
120
+## Slicing
121
+
122
+You can get a slice of a string with slicing syntax:
123
124
+```rust
125
+let dog = "hachiko";
126
+let hachi = &dog[0..5];
127
+```
128
129
+But note that these are _byte_ offsets, not _character_ offsets. So
130
+this will fail at runtime:
131
132
+```rust,should_panic
133
+let dog = "忠犬ハチ公";
134
+let hachi = &dog[0..2];
135
136
137
+with this error:
138
139
+```text
140
+thread '<main>' panicked at 'index 0 and/or 2 in `忠犬ハチ公` do not lie on
141
+character boundary'
142
143
144
## Concatenation
145
146
If you have a `String`, you can concatenate a `&str` to the end of it:
0 commit comments