How can I split a string between multiple delineating characters?

我只是一个虾纸丫 提交于 2019-12-24 02:04:22

问题


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. The data entry I'm working with looks like this...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; so I can insert those values into the attributes of the XML. Would this be a situation appropriate for RegEx? Or would I be better off using Substring, with an index of *?

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.


回答1:


You can use String.Split()

string[] words = @"e11*70/157*1999/101*1090*04".Split('*');



回答2:


I think this should solve your ptoblem :

string content = @"11*70/157*1999/101*1090*04";
     string [] split = words.Split('*');



回答3:


You could use the Split method to create a string array like so:

string txt = "e11*70/157*1999/101*1090*04";
foreach (string s in txt.Split('*')){
   DoSomething(s);
}


来源:https://stackoverflow.com/questions/5951114/how-can-i-split-a-string-between-multiple-delineating-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!