Julia - Trim string whitespace and check length

lstrip for leading whitespace, rstrip for trailing whitespace, stripfor both.

There is an isempty function for julia as well:

isempty("")
>> true

Perhaps you should check out the Julia docs for other string-related functions (https://docs.julialang.org/en/stable/ & https://docs.julialang.org/en/stable/manual/strings/)


For the start/end of a string you have

lstrip(string)
rstrip(string)

if you need to take everything out I recommend you use something like

a = "a b c d e f"
join(map(x -> isspace(a[x]) ? "" : a[x], 1:length(a)))

because sometimes you can get strings that include some weird whitespaces that wont match " " or ' ' as is shown here

Edit

filter(x -> !isspace(x), a)

as suggested by Fengyang Wang, is even better

Tags:

String

Julia