diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-03-12 18:59:46 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-03-12 18:59:46 -0500 |
commit | 6ad9774189fbd64b2f2c9519f4513ab34b0c3809 (patch) | |
tree | d6c90700131d5b28e898881f13e2a05612e4703f /exercises/06_strings.zig | |
parent | be36352572ddb18218e1830e49316c259dea5e8c (diff) | |
download | ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.tar.gz ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.tar.bz2 ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.tar.xz ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.zip |
"999 is enough for anybody" triple-zero padding (#18)
When I hit 999 exercises, I will finally have reached the ultimate
state of soteriological release and no more exercises will be needed.
The cycle will be complete. All that will be left is perfect quietude,
freedom, and highest happiness.
Diffstat (limited to 'exercises/06_strings.zig')
-rw-r--r-- | exercises/06_strings.zig | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/exercises/06_strings.zig b/exercises/06_strings.zig deleted file mode 100644 index 6258816..0000000 --- a/exercises/06_strings.zig +++ /dev/null @@ -1,48 +0,0 @@ -// -// Now that we've learned about arrays, we can talk about strings. -// -// We've already seen Zig string literals: "Hello world.\n" -// -// Zig stores strings as arrays of bytes. -// -// const foo = "Hello"; -// -// Is the same as: -// -// const foo = [_]u8{ 'H', 'e', 'l', 'l', 'o' }; -// -const std = @import("std"); - -pub fn main() void { - const ziggy = "stardust"; - - // (Problem 1) - // Use array square bracket syntax to get the letter 'd' from - // the string "stardust" above. - const d: u8 = ziggy[???]; - - // (Problem 2) - // Use the array repeat '**' operator to make "ha ha ha ". - const laugh = "ha " ???; - - // (Problem 3) - // Use the array concatenation '++' operator to make "Major Tom". - // (You'll need to add a space as well!) - const major = "Major"; - const tom = "Tom"; - const major_tom = major ??? tom; - - // That's all the problems. Let's see our results: - std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom }); - // Keen eyes will notice that we've put 'u' and 's' inside the '{}' - // placeholders in the format string above. This tells the - // print() function to format the values as a UTF-8 character and - // UTF-8 strings respectively. If we didn't do this, we'd see '100', - // which is the decimal number corresponding with the 'd' character - // in UTF-8. (And an error in the case of the strings.) - // - // While we're on this subject, 'c' (ASCII encoded character) - // would work in place for 'u' because the first 128 characters - // of UTF-8 are the same as ASCII! - // -} |