我正在尝试显示当前在会议室中的主持人。这就是我所做的:
puts m.roster.keys.map { |v| "Mods in the room are: #{if m.roster[v].x[0].role.to_s.include?('moderator') then v end}" }.join(", ")
结果是:
Mods in the room are: , , User3, User4, , , , , , , User11, , User13
有没有办法摆脱那些不受欢迎的逗号,但保留逗号分隔每个逗号,如下所示?
Mods in the room are: User3, User4, User11, User 13
答案 0 :(得分:1)
这样的事情可能是你正在寻找的东西:
puts "Mods in the room are: #{m.roster.select {|k,v| v.x[0].role.to_s.include?('moderator') }.keys.join(", ")}"
我相信会给你一个主持人名单。
答案 1 :(得分:1)
我没有关注您的代码,但您可以按照以下方式修改错误结果。
private class Row
{
public string ItemName { get; set; }
public int Quantity { get; set; }
public double Price { get; set; }
public Row(string i, int q, double p)
{
this.ItemName = i;
this.Quantity = q;
this.Price = p;
}
}
private List<Row> rows = new List<Row>();
private void Form1_Load(object sender, EventArgs e)
{
// instead, here you will add your rows from SQL
rows.AddRange(new Row[]
{
new Row("item1", 0, 500),
new Row("item2", 0, 400),
new Row("item3", 0, 850)
});
this.dataGridView1.DataSource = rows;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
Add.Click += quantityChangeClick;
Minus.Click += quantityChangeClick;
}