Reputation: 5137
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 appreciated.
Upvotes: 0
Views: 383
Reputation: 8116
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
Upvotes: 1
Reputation: 38376
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"
Upvotes: 8