File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " strings"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ // Creating a string
3
+ // Using to_string()
4
+ let mut _string = String :: new ( ) ;
5
+ let data = "initial contents" ;
6
+ _string = data. to_string ( ) ;
7
+
8
+ drop ( _string) ;
9
+ // Using String::from()
10
+ let mut _string = String :: from ( "initial contents" ) ;
11
+ drop ( _string) ;
12
+
13
+ // Updating a String
14
+ let mut _string = String :: from ( "foo" ) ;
15
+ let string_2 = "bar" ;
16
+
17
+ _string. push_str ( string_2) ;
18
+ drop ( _string) ;
19
+
20
+ // Indexing into strings
21
+ let _string = String :: from ( "Hello World" ) ;
22
+
23
+ // Slicing strings
24
+ let _world = & _string[ 6 ..] ;
25
+
26
+ // Iterating over String
27
+ for character in _string. chars ( ) {
28
+ println ! ( "{character}" ) ;
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments