开发者

How can I split a string between multiple delineating characters?

开发者 https://www.devze.com 2023-03-05 01:31 出处:网络
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*199

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 bett开发者_JS百科er 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.


You can use 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('*');


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消