So the following code can left pad a string with spaces keeping a max length of max_len (spaces and string included).
max_len = 20;
spacing_arg = ['% ', max_len,'s'];
padded_string = sprintf(spacing_arg, str);
Now how to do it efficiently with right padding?
Is this what you mean?
max_len = 20;
spacing_arg = ['%-', num2str(max_len),'s'];
padded_string = sprintf(spacing_arg, str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With