我在Name
中有列:
public async Task<IHttpActionResult> UploadProfilePic([FromForm]IFormFile uploadFile))
{
// do something with uploadFile.Name
}
我在@columns
中有分隔符:
my @columns =('column1', 'column2', 'column3');
我想一一插入列之间的分隔符:
@separators
我的解决方法是:
my @separators = (',', '|');
我这里有三列和两个分隔符,如何在column1,column2|column
列之间插入(@columns »~» (|@separators,"")).join("")
分隔符?
答案 0 :(得分:8)
假设@separators
具有正确数量的值,则可以使用roundrobin
。
roundrobin( @columns, @separators ).flat.join()
答案 1 :(得分:5)
因此,它应该适用于@columns
或@separators
的任意长度:
首先,我们使用>>,>>
超操作符创建列表列表。
(@columns >>,>> @separators)
哪个给:
[("column1", ","), ("column2", "|"), ("column3", ",")]
然后,我们使用一张清单将其展平为一个列表。
(@columns >>,>> @separators).map( |* )
哪个给:
("column1", ",", "column2", "|", "column3", ",").Seq
然后我们得到除最后一个值以外的所有值的数组:
(@columns >>,>> @separators).map(|*).head(*-1)
对于:
("column1", ",", "column2", "|", "column3")
最后一无所有:
(@columns >>,>> @separators).map(|*).head(*-1).join("")
最终结果:
column1,column2|column3
更改列数或分隔符的数目不会有任何不同。
答案 2 :(得分:0)
可能是另一种解决方案:
my @columns =('column1', 'column2', 'column3');
my @separators = (',', '|');
sub sep { $^a ~@separators[$++] ~$^b};
say [[&sep]] @columns;
say [[&sep]] @columns; # but another call cause error
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
in sub sep at <unknown file> line 1
in block <unit> at <unknown file> line 1
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
in sub sep at <unknown file> line 1
in block <unit> at <unknown file> line 1
column1column2column3