[英]How can I split a string between multiple delineating characters?
I'm working on a program that will parse off chunks off data from a CSV file, and populate it into the attributes of an XML document. 我正在开发一个程序,该程序将从CSV文件中解析出大量数据,并将其填充到XML文档的属性中。 The data entry I'm working with looks like this...e11*70/157*1999/101*1090*04. 我正在使用的数据条目如下所示:e11 * 70/157 * 1999/101 * 1090 * 04。 I want to break that up, using the asterisks as the reference to split it into e11, 70/157, 1999/101, etc; 我想用星号作为参考将其分解为e11、70 / 157、1999 / 101等。 so I can insert those values into the attributes of the XML. 因此我可以将这些值插入XML的属性中。 Would this be a situation appropriate for RegEx? 这是否适合RegEx? Or would I be better off using Substring, with an index of *? 还是我最好使用索引为*的Substring?
Thanks so much for the assistance. 非常感谢您的协助。 I'm new to the programming world, and have found sites such as these to be a extremely valuable resource. 我是编程世界的新手,并且发现诸如此类的网站是非常宝贵的资源。
您可以使用String.Split()
string[] words = @"e11*70/157*1999/101*1090*04".Split('*');
I think this should solve your ptoblem : 我认为这应该解决您的问题:
string content = @"11*70/157*1999/101*1090*04";
string [] split = words.Split('*');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.