开发者

Extract portion of filename C#

Hey, I have filenames like this: R303717COMP_148A2075_20100520_19230.txt (the R number and the other numbers vary, but same format)

I would like to extract the 148A2075 and 20100520 separately into variables for use inserting in a column of my sqlite db.

any help is a开发者_如何学JAVAppreciated.


Sounds like a job for the String.Split() method. Example:

string name = "R303717COMP_148A2075_20100520_19230.txt";
string[] tokens = name.Split('_');

// tokens[1] == "148A2075"
// tokens[2] == "20100520"


string filename = "R303717COMP_148A2075_20100520_19230.txt";

string[] chunks = filename.Split('_');

Console.Writeline(chunks[1]); // this prints 148A2075 

Console.Writeline(chunks[2]); // this prints 20100520 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜