Fixed missing semicolons, and grammar mistakes

This commit is contained in:
Tanish-Eagle 2022-09-21 22:45:38 +05:30
parent 055122f4fb
commit d228721809
1 changed files with 24 additions and 24 deletions

View File

@ -1,4 +1,4 @@
# formating
# Formatting
## Positional arguments
@ -6,7 +6,7 @@
```rust,editable
/* Fill in the blanks */
fn main() {
println!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob");// => Alice, this is Bob. Bob, this is Alice
println!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob"); // => Alice, this is Bob. Bob, this is Alice
assert_eq!(format!("{1}{0}", 1, 2), __);
assert_eq!(format!(__, 1, 2), "2112");
println!("Success!");
@ -25,10 +25,10 @@ fn main() {
assert_eq!(format!(__,a = "a", b = 'b', c = 3 ), "a 3 b");
/* Fix the error */
// named argument must be placed after other arguments
// Named argument must be placed after other arguments
println!("{abc} {1}", abc = "def", 2);
println!("Success!")
println!("Success!");
}
```
@ -37,7 +37,7 @@ fn main() {
3.🌟🌟 By default, you can pad string with spaces
```rust,editable
fn main() {
// the following two are padding with 5 spaces
// The following two are padding with 5 spaces
println!("Hello {:5}!", "x"); // => "Hello x !"
println!("Hello {:1$}!", "x", 5); // => "Hello x !"
@ -45,24 +45,24 @@ fn main() {
assert_eq!(format!("Hello __!", 5, "x"), "Hello x !");
assert_eq!(format!("Hello __!", "x", width = 5), "Hello x !");
println!("Success!")
println!("Success!");
}
```
4.🌟🌟🌟 Left align, right align, pad with specified characters.
```rust,editable
fn main() {
// left align
// Left align
println!("Hello {:<5}!", "x"); // => Hello x !
// right align
// Right align
assert_eq!(format!("Hello __!", "x"), "Hello x!");
// center align
// Center align
assert_eq!(format!("Hello __!", "x"), "Hello x !");
// left align, pad with '&'
// Left align, pad with '&'
assert_eq!(format!("Hello {:&<5}!", "x"), __);
println!("Success!")
println!("Success!");
}
```
@ -78,10 +78,10 @@ fn main() {
assert!(format!("{number:0>width$}", number=1, width=6) == __);
println!("Success!")
}
;}
```
## precision
## Precision
6.🌟🌟 Floating point precision
```rust,editable
@ -95,11 +95,11 @@ fn main() {
assert_eq!(format!("__", v), "+3.14");
assert_eq!(format!("__", v), "3");
println!("Success!")
println!("Success!");
}
```
7.🌟🌟🌟 string length
7.🌟🌟🌟 String length
```rust,editable
fn main() {
let s = "Hello, world!";
@ -108,11 +108,11 @@ fn main() {
assert_eq!(format!("Hello __!", 3, "abcdefg"), "Hello abc!");
println!("Success!")
println!("Success!");
}
```
## binary, octal, hex
## Binary, octal, hex
- format!("{}", foo) -> "3735928559"
- format!("0x{:X}", foo) -> "0xDEADBEEF"
@ -126,15 +126,15 @@ fn main() {
assert_eq!(format!("__", 27), "0x1b");
assert_eq!(format!("__", 27), "0x1B");
println!("{:x}!", 27); // hex with no prefix => 1b
println!("{:x}!", 27); // Hex with no prefix => 1b
println!("{:#010b}", 27); // pad binary with 0, width = 10, => 0b00011011
println!("{:#010b}", 27); // Pad binary with 0, width = 10, => 0b00011011
println!("Success!")
println!("Success!");
}
```
## Capture the environments
## Capture the environment
9.🌟🌟🌟
```rust,editable
fn get_person() -> String {
@ -168,15 +168,15 @@ fn main() {
**Example**
```rust,editable
fn main() {
// exponent
// Exponent
println!("{:2e}", 1000000000); // => 1e9
println!("{:2E}", 1000000000); // => 1E9
// pointer address
// Pointer address
let v= vec![1, 2, 3];
println!("{:p}", v.as_ptr()); // => 0x600002324050
// escape
// Escape
println!("Hello {{}}"); // => Hello {}
}
```