How can I convert comma separated string into a List

前端 未结 11 2147
我寻月下人不归
我寻月下人不归 2020-12-07 09:16
string tags = \"9,3,12,43,2\"

List TagIds = tags.Split(\',\');

This doesn\'t work cause the split method returns a string[]

11条回答
  •  眼角桃花
    2020-12-07 09:58

    It's simple. First split the string. Trim blank space present after comma(,). Then use system defined ToList()

    string inputText = "text1, text2"
    

    To remove the space after ',' and convert this comma separated text to List

    List resultList = (inputText.Split(',')).Select(t => t).ToList();
    

提交回复
热议问题