Remove spaces at both ends
Remove the spaces before and after a name. A space between two words stays in place. These examples use ordinary spaces.
std.mem.trim
Simple example
Trim the single letter.
Start' a '
Resulta
const std = @import("std");
pub fn main() !void {
std.debug.print("{s}\n", .{std.mem.trim(u8, " a ", " ")});
}
a
Advertisements
Everyday examples
Remove the extra spaces copied around a ticket number.
Start' B12 '
ResultB12
const std = @import("std");
pub fn main() !void {
std.debug.print("{s}\n", .{std.mem.trim(u8, " B12 ", " ")});
}
B12
Clean up the outside spaces on a shelf label.
Start' Red Apples '
ResultRed Apples
const std = @import("std");
pub fn main() !void {
std.debug.print("{s}\n", .{std.mem.trim(u8, " Red Apples ", " ")});
}
Red Apples
Clean up a name copied from a signup sheet.
Start' Ana '
ResultAna
const std = @import("std");
pub fn main() !void {
std.debug.print("{s}\n", .{std.mem.trim(u8, " Ana ", " ")});
}
Ana