zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

string_literals.zig (924B) - Raw


      1 const print = @import("std").debug.print;
      2 const mem = @import("std").mem; // will be used to compare bytes
      3 
      4 pub fn main() void {
      5     const bytes = "hello";
      6     print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8
      7     print("{d}\n", .{bytes.len}); // 5
      8     print("{c}\n", .{bytes[1]}); // 'e'
      9     print("{d}\n", .{bytes[5]}); // 0
     10     print("{}\n", .{'e' == '\x65'}); // true
     11     print("{d}\n", .{'\u{1f4a9}'}); // 128169
     12     print("{d}\n", .{'💯'}); // 128175
     13     print("{u}\n", .{'âš¡'});
     14     print("{}\n", .{mem.eql(u8, "hello", "h\x65llo")}); // true
     15     print("{}\n", .{mem.eql(u8, "💯", "\xf0\x9f\x92\xaf")}); // also true
     16     const invalid_utf8 = "\xff\xfe"; // non-UTF-8 strings are possible with \xNN notation.
     17     print("0x{x}\n", .{invalid_utf8[1]}); // indexing them returns individual bytes...
     18     print("0x{x}\n", .{"💯"[1]}); // ...as does indexing part-way through non-ASCII characters
     19 }
     20 
     21 // exe=succeed