locked
Extract A Portion Of A String RRS feed

  • Question

  • User1402230106 posted

    I am using the below to capture the 1st group after the . in a filename.  And the filenames are always in this syntax

    marxdiaz.M04Y15.wedding

    calpuper.M02Y14.birthday

    var se = ftm.Split('.');
    string ssee= se[1].ToUpper();

    Which this will return M02Y14, now I need to take that a step further (and assign to a diff variable) ONLY the 3rd position in a string, so for example from M02, I would only want to extract the 2 from the string.

    Monday, May 4, 2015 2:23 PM

Answers

  • User2053451246 posted

    var se = ftm.Split('.');
    string ssee= se[1].ToUpper();

    var newVariable = ssee.Substring(2, 1);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2015 2:57 PM

All replies

  • User2053451246 posted

    var se = ftm.Split('.');
    string ssee= se[1].ToUpper();

    var newVariable = ssee.Substring(2, 1);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2015 2:57 PM
  • User-1078840699 posted

    Just split on the -  character and later you can access them. Use string.Split(char[])

    string str  = "123-4567-9012";
    string[] arr = str.Split('-');

    it will result in:

    arr[0] = "123";
    arr[1] = "4567";
    arr[2] = "9012"

    Also, do check this link

    Monday, May 4, 2015 3:43 PM