简体   繁体   English

删除字符串中的逗号,然后将每个逗号分隔的值插入字符串中

[英]Remove Commas in a string and insert each comma-separated value into a string

How would I do this? 我该怎么做?

To bring it into some better context, I'm having a value from an XML attribute and I want each individual value to be added to an array of strings and each of those values is separated by commas 为了将其带入更好的上下文,我从XML属性中获取一个值,并且希望将每个单独的值添加到字符串数组中,并且每个值都用逗号分隔

Is string.Split what you're after? string.Split您所追求的吗? It's not entirely obvious from your question. 从您的问题来看,这并不完全明显。

string text = "a,b,c";
string[] bits = text.Split(',');

foreach (string bit in bits)
{
    Console.WriteLine(bit);
}
        string input = Console.ReadLine();
        char splitter = ',' ;
        string[] output = input.Split(splitter);
        foreach (string t in output)
        {
            Console.WriteLine(t);
        }

how are these values stored in the xml? 这些值如何存储在xml中? If you know the structure of the xml you can easily extract the info..i din quite get the next part. 如果您知道xml的结构,则可以轻松提取info..i din,获得下一部分。 you want to make a CSV but u also want to store it in an array.but wont the array itself seperate the values? 您想制作CSV,但您也想将其存储在数组中。但是数组本身不会将值分开吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM