none
Extract Part of the value using C# code RRS feed

  • Question

  • Hi,

       I have an existing code in SSIS to get error column name. Following is the code I currently have ,

                Row.ColumnName = componentMetaData130.GetIdentificationStringByID(Row.ErrorColumn);

    and the result is 

    'tablename(transform).Outputs[Derived Column Output].Columns[lu_time] '  

    Can you please help me to get only the last part of this value using C# code. My expected result is lu_time.


    Sunday, July 15, 2018 11:45 PM

Answers

  • Resolved using this code. Thanks a ton

    string CN= componentMetaData130.GetIdentificationStringByID(Row.ErrorColumn);
                string[] parts = CN.Split(new string[] { "Columns[" }, StringSplitOptions.None);
                Row.ColumnName = parts[1].Replace("]","");

    • Marked as answer by Hello_123456 Monday, July 16, 2018 3:45 AM
    Monday, July 16, 2018 3:45 AM

All replies

  • I would probably Split on "Columns[" and get it that way. Like this:

    string[] parts = Row.ColumnName.Split(new string[] { "Columns[" }, StringSplitOptions.None);
    string result = parts.Last().Substring(0, parts.Last().Length - 2);


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com


    Monday, July 16, 2018 1:30 AM
    Moderator
  • Thanks for your response.

    I am getting error for using "Last()" . string[] does not contain a definition for 'last' 

      string CN= Row.ColumnName = componentMetaData130.GetIdentificationStringByID(Row.ErrorColumn);
                string[] parts = CN.Split(new string[] { "Columns[" }, StringSplitOptions.None);
                string result = parts.Last().Substring(0, parts.Last().Length - 2);


    Monday, July 16, 2018 3:02 AM
  • Resolved using this code. Thanks a ton

    string CN= componentMetaData130.GetIdentificationStringByID(Row.ErrorColumn);
                string[] parts = CN.Split(new string[] { "Columns[" }, StringSplitOptions.None);
                Row.ColumnName = parts[1].Replace("]","");

    • Marked as answer by Hello_123456 Monday, July 16, 2018 3:45 AM
    Monday, July 16, 2018 3:45 AM
  • Thanks for your response.

    I am getting error for using "Last()" . string[] does not contain a definition for 'last' 

      string CN= Row.ColumnName = componentMetaData130.GetIdentificationStringByID(Row.ErrorColumn);
                string[] parts = CN.Split(new string[] { "Columns[" }, StringSplitOptions.None);
                string result = parts.Last().Substring(0, parts.Last().Length - 2);



    I don't know why that gave you an error ... parts.Last() is valid and has been for many years (as far back as Visual Studio 2008 I think). What version of VS are you using?

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Monday, July 16, 2018 5:08 AM
    Moderator