Join a string using delimiters

后端 未结 24 1654
北海茫月
北海茫月 2020-12-05 09:57

What is the best way to join a list of strings into a combined delimited string. I\'m mainly concerned about when to stop adding the delimiter. I\'ll use C# for my example

24条回答
  •  旧时难觅i
    2020-12-05 10:54

    Seen the Python answer like 3 times, but no Ruby?!?!?

    the first part of the code declares a new array. Then you can just call the .join() method and pass the delimiter and it will return a string with the delimiter in the middle. I believe the join method calls the .to_s method on each item before it concatenates.

    ["ID", "Description", "Active"].join(",")
    >> "ID, Description, Active"
    

    this can be very useful when combining meta-programming with with database interaction.

    does anyone know if c# has something similar to this syntax sugar?

提交回复
热议问题