To create an array with empty strings ['a', '', 'b', '', 'c']
(not one space strings ' '
), using %W
I can use %W[a #{} b #{} c]
, also I can concatenate arrays, but is it possible to create array with empty strings using just %w[]
?
For example, str = "" creates a string scalar that contains no characters. str = strings( n ) returns an n -by- n string array. Each element is a string with no characters.
To declare an empty array for a type variable, set the array's type to Type[] , e.g. const arr: Animal[] = [] . Any elements you add to the array need to conform to the specific type, otherwise you would get an error. Copied!
A couple of options
%W[a b c #{''} z]
%W[a b c] << " "
(I know this isn't using the %w{}
syntax, but for good measure:
'a,b,c,,z'.split(',')
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