Suppose I have a list = [4, 1, 8, 3], I want to print all the elements of list in the same line like:
4 1 8 3
I checked this regular expression ^\[|,|\] on regexr.com and it selected everything except the elements. So I was expecting
print(list.toString().replaceAll('^\[|,|\]', ''));
to match above output, but it outputs:
[4, 1, 8, 3]
How do achieve the desired output?
Note that I cannot have whitespace around the output so something like this won't work:
list.forEach((element) => stdout.write('$element '));
Edit: I got it to work with
print(list
.toString()
.replaceAll(',', '')
.replaceAll('[', '')
.replaceAll(']', ''));
is this the best that can be done?