File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ in a controlled repository now.
8
8
* ` datatypes ` : examples of various datatype thingies
9
9
* ` structs.rs ` : struct and enum examples
10
10
* ` arrays.rs ` : array and vector examples
11
+ * ` strings.rs ` : string and str examples
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ let mut s = String :: new ( ) ;
3
+ s. push ( 'a' ) ;
4
+ s. push ( 'b' ) ;
5
+ println ! ( "{}" , s) ;
6
+
7
+ let t = 5u32 . to_string ( ) ;
8
+ println ! ( "{}" , t) ;
9
+ let t = "ab" . to_string ( ) ;
10
+ assert_eq ! ( s, t) ;
11
+
12
+ let u = format ! ( "{}{}" , 'a' , 'b' ) ;
13
+ assert_eq ! ( s, u) ;
14
+
15
+ /*
16
+ for i in 0..s.len() {
17
+ println!("{}", s[i]);
18
+ }
19
+ */
20
+
21
+ for c in s. chars ( ) {
22
+ println ! ( "{}" , c) ;
23
+ }
24
+
25
+ let w: & str = "ab" ;
26
+ assert_eq ! ( s, w) ;
27
+
28
+ let w: & str = & s;
29
+ println ! ( "{}" , w) ;
30
+ }
You can’t perform that action at this time.
0 commit comments