locked
Parsing A FileName With C# RRS feed

  • Question

  • User-1056855865 posted

    Greetings - we are using a web portal to have users submit a word document (either .doc or .docx extension) that part of the filename is S11B01.doc - it always ends like this - student number, and block number.  It's always 2 digits student number and always 2 digit block number.  How can I parse the file name and store in two variables studentID = 11 and blockID = 01?

    Sunday, October 14, 2018 5:18 PM

Answers

  • User303363814 posted
    var justName = Path.GetFileNameWithoutExtension(theFileName);
    var studentID = justName.Substring(1,2);
    var blockID = justName.Substring(4,2);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 14, 2018 10:41 PM