Join a string using delimiters

后端 未结 24 1645
北海茫月
北海茫月 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条回答
  •  长情又很酷
    2020-12-05 10:48

    Since you tagged this language agnostic,

    This is how you would do it in python

    # delimiter can be multichar like "| trlalala |"
    delimiter = ";"
    # sequence can be any list, or iterator/generator that returns list of strings
    result = delimiter.join(sequence)
    #result will NOT have ending delimiter 
    

    Edit: I see I got beat to the answer by several people. Sorry for dupication

提交回复
热议问题