From cf0d050e81f6c622c96d9b4d307d0106b3f023b2 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 8 Sep 2021 05:46:23 -0700 Subject: [PATCH] Rename some string formatting outputs Also rebuild output --- .../string-formatting/string-formatting.go | 6 +- .../string-formatting/string-formatting.hash | 4 +- .../string-formatting/string-formatting.sh | 8 +- public/string-formatting | 96 +++++++++---------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/examples/string-formatting/string-formatting.go b/examples/string-formatting/string-formatting.go index ba3704d..2e7e6ca 100644 --- a/examples/string-formatting/string-formatting.go +++ b/examples/string-formatting/string-formatting.go @@ -88,15 +88,15 @@ func main() { fmt.Printf("width2: |%6.2f|%6.2f|\n", 1.2, 3.45) // To left-justify, use the `-` flag. - fmt.Printf("float4: |%-6.2f|%-6.2f|\n", 1.2, 3.45) + fmt.Printf("width3: |%-6.2f|%-6.2f|\n", 1.2, 3.45) // You may also want to control width when formatting // strings, especially to ensure that they align in // table-like output. For basic right-justified width. - fmt.Printf("width3: |%6s|%6s|\n", "foo", "b") + fmt.Printf("width4: |%6s|%6s|\n", "foo", "b") // To left-justify use the `-` flag as with numbers. - fmt.Printf("str4: |%-6s|%-6s|\n", "foo", "b") + fmt.Printf("width5: |%-6s|%-6s|\n", "foo", "b") // So far we've seen `Printf`, which prints the // formatted string to `os.Stdout`. `Sprintf` formats diff --git a/examples/string-formatting/string-formatting.hash b/examples/string-formatting/string-formatting.hash index a8cc209..20bbc6c 100644 --- a/examples/string-formatting/string-formatting.hash +++ b/examples/string-formatting/string-formatting.hash @@ -1,2 +1,2 @@ -99fb572787ffa93dad9c491aec5ce5c7a7516081 -L6BkGeaN_p4 +2297335ea52cc0ed960153b891d35252636308b4 +EZCZX1Uwp6D diff --git a/examples/string-formatting/string-formatting.sh b/examples/string-formatting/string-formatting.sh index 1218895..daa100c 100644 --- a/examples/string-formatting/string-formatting.sh +++ b/examples/string-formatting/string-formatting.sh @@ -14,11 +14,11 @@ float3: 1.234000E+08 str1: "string" str2: "\"string\"" str3: 6865782074686973 -pointer: 0xc420014090 +pointer: 0xc0000ba000 width1: | 12| 345| width2: | 1.20| 3.45| -float4: |1.20 |3.45 | -width3: | foo| b| -str4: |foo |b | +width3: |1.20 |3.45 | +width4: | foo| b| +width5: |foo |b | sprintf: a string io: an error diff --git a/public/string-formatting b/public/string-formatting index 00a14de..8bd5dd2 100644 --- a/public/string-formatting +++ b/public/string-formatting @@ -43,7 +43,7 @@ common string formatting tasks.

- +
package main
 
@@ -98,7 +98,7 @@ an instance of our point struct.

     p := point{1, 2}
-    fmt.Printf("%v\n", p)
+    fmt.Printf("struct1: %v\n", p)
 
@@ -112,7 +112,7 @@ include the struct’s field names.

-    fmt.Printf("%+v\n", p)
+    fmt.Printf("struct2: %+v\n", p)
 
@@ -127,7 +127,7 @@ would produce that value.

-    fmt.Printf("%#v\n", p)
+    fmt.Printf("struct3: %#v\n", p)
 
@@ -140,7 +140,7 @@ would produce that value.

-    fmt.Printf("%T\n", p)
+    fmt.Printf("type: %T\n", p)
 
@@ -153,7 +153,7 @@ would produce that value.

-    fmt.Printf("%t\n", true)
+    fmt.Printf("bool: %t\n", true)
 
@@ -167,7 +167,7 @@ Use %d for standard, base-10 formatting.

-    fmt.Printf("%d\n", 123)
+    fmt.Printf("int: %d\n", 123)
 
@@ -180,7 +180,7 @@ Use %d for standard, base-10 formatting.

-    fmt.Printf("%b\n", 14)
+    fmt.Printf("bin: %b\n", 14)
 
@@ -194,7 +194,7 @@ given integer.

-    fmt.Printf("%c\n", 33)
+    fmt.Printf("char: %c\n", 33)
 
@@ -207,7 +207,7 @@ given integer.

-    fmt.Printf("%x\n", 456)
+    fmt.Printf("hex: %x\n", 456)
 
@@ -221,7 +221,7 @@ floats. For basic decimal formatting use %f.

-    fmt.Printf("%f\n", 78.9)
+    fmt.Printf("float1: %f\n", 78.9)
 
@@ -235,8 +235,8 @@ different versions of) scientific notation.

-    fmt.Printf("%e\n", 123400000.0)
-    fmt.Printf("%E\n", 123400000.0)
+    fmt.Printf("float2: %e\n", 123400000.0)
+    fmt.Printf("float3: %E\n", 123400000.0)
 
@@ -249,7 +249,7 @@ different versions of) scientific notation.

-    fmt.Printf("%s\n", "\"string\"")
+    fmt.Printf("str1: %s\n", "\"string\"")
 
@@ -262,7 +262,7 @@ different versions of) scientific notation.

-    fmt.Printf("%q\n", "\"string\"")
+    fmt.Printf("str2: %q\n", "\"string\"")
 
@@ -277,7 +277,7 @@ per byte of input.

-    fmt.Printf("%x\n", "hex this")
+    fmt.Printf("str3: %x\n", "hex this")
 
@@ -290,7 +290,7 @@ per byte of input.

-    fmt.Printf("%p\n", &p)
+    fmt.Printf("pointer: %p\n", &p)
 
@@ -308,7 +308,7 @@ spaces.

-    fmt.Printf("|%6d|%6d|\n", 12, 345)
+    fmt.Printf("width1: |%6d|%6d|\n", 12, 345)
 
@@ -324,7 +324,7 @@ width.precision syntax.

-    fmt.Printf("|%6.2f|%6.2f|\n", 1.2, 3.45)
+    fmt.Printf("width2: |%6.2f|%6.2f|\n", 1.2, 3.45)
 
@@ -337,7 +337,7 @@ width.precision syntax.

-    fmt.Printf("|%-6.2f|%-6.2f|\n", 1.2, 3.45)
+    fmt.Printf("width3: |%-6.2f|%-6.2f|\n", 1.2, 3.45)
 
@@ -352,7 +352,7 @@ table-like output. For basic right-justified width.

-    fmt.Printf("|%6s|%6s|\n", "foo", "b")
+    fmt.Printf("width4: |%6s|%6s|\n", "foo", "b")
 
@@ -365,7 +365,7 @@ table-like output. For basic right-justified width.

-    fmt.Printf("|%-6s|%-6s|\n", "foo", "b")
+    fmt.Printf("width5: |%-6s|%-6s|\n", "foo", "b")
 
@@ -380,7 +380,7 @@ and returns a string without printing it anywhere.

-    s := fmt.Sprintf("a %s", "string")
+    s := fmt.Sprintf("sprintf: a %s", "string")
     fmt.Println(s)
 
@@ -395,7 +395,7 @@ and returns a string without printing it anywhere.

-    fmt.Fprintf(os.Stderr, "an %s\n", "error")
+    fmt.Fprintf(os.Stderr, "io: an %s\n", "error")
 }
 
@@ -412,29 +412,29 @@ and returns a string without printing it anywhere.

$ go run string-formatting.go
-{1 2}
-{x:1 y:2}
-main.point{x:1, y:2}
-main.point
-true
-123
-1110
-!
-1c8
-78.900000
-1.234000e+08
-1.234000E+08
-"string"
-"\"string\""
-6865782074686973
-0x42135100
-|    12|   345|
-|  1.20|  3.45|
-|1.20  |3.45  |
-|   foo|     b|
-|foo   |b     |
-a string
-an error
+struct1: {1 2} +struct2: {x:1 y:2} +struct3: main.point{x:1, y:2} +type: main.point +bool: true +int: 123 +bin: 1110 +char: ! +hex: 1c8 +float1: 78.900000 +float2: 1.234000e+08 +float3: 1.234000E+08 +str1: "string" +str2: "\"string\"" +str3: 6865782074686973 +pointer: 0xc0000ba000 +width1: | 12| 345| +width2: | 1.20| 3.45| +width3: |1.20 |3.45 | +width4: | foo| b| +width5: |foo |b | +sprintf: a string +io: an error @@ -453,7 +453,7 @@ and returns a string without printing it anywhere.