#how to check string

1 messages · Page 1 of 1 (latest)

void mesa
#

std.mem.span can turn a null terminated string into a slice

#

You really shouldn't use std.os.argv though, its not portable

spring wraith
#

argv returns a [*:0], which is a pointer that ends with the null terminator character 0. This is often used for strings in c. When you use asBytes on this type, it provides the bytes of the pointer. The bytes of the pointer pointing to the string are not equal to "run". Instead, you can use span as suggested by Jodi to convert the pointer into a slice, which then can be passed to the eql function.

silk perch
#

the conversions of these types are deceptively tricky for beginners. Are there any good resources that can help grapple with this topic?

spring wraith
heavy grotto
#
    if (std.mem.eql(u8, result, "run")) {
        print("found arg run\n", .{});
    }```
```src/main.zig:19:34: error: index syntax required for unknown-length pointer type '[*:0]u8'
    const result = std.os.argv[1].*;```
void mesa
#

The compiler would have no way to know how big the array its pointing to is