locked
if (File_Extenention.Length > 1) RRS feed

  • Question

  • User2045233432 posted

    string file = GridView.DataKeys[e.Row.RowIndex].Values[1].ToString();

    string[] File_Extenention= file.Split('.');

    if (File_Extenention.Length > 1)

    {//do some code}

    what does this line if (File_Extenention.Length > 1) mean ?

    Sunday, July 27, 2014 4:50 PM

Answers

  • User1428246847 posted

    'hallo.txt' will be split into 'hallo' and 'text'; the split() returns an array with 2 strings.

    'hallo.null_name.txt' will be split into 'hallo', 'null_name' and 'txt'; the split() returns an array with 3 strings.

    if (File_Extenention.Length > 1)
    {
    }

    If there is more than one element in the array, the file has an extension.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 28, 2014 11:04 AM

All replies

  • User-1360095595 posted

    File_Extenention is an array. That line of code is checking if the array has any elements in it. So basically making sure that the split() "worked"?

    Sunday, July 27, 2014 4:58 PM
  • User-1716253493 posted
    File and extension is separated by
    dot. If the value contain filename
    with extension will be splitted into
    two parts or more.
    Sunday, July 27, 2014 5:06 PM
  • User2045233432 posted

    File_Extenention is an array. That line of code is checking if the array has any elements in it. So basically making sure that the split() "worked"?

    elements of what ?  it all have only .pdf or .doc

    how it will know if that file has data or not !

    Sunday, July 27, 2014 5:13 PM
  • User-1360095595 posted

    Gogle/bing string.Split(). Maybe that will clarify what I'm trying to tell you. 

    Sunday, July 27, 2014 5:16 PM
  • User1428246847 posted

    'hallo.txt' will be split into 'hallo' and 'text'; the split() returns an array with 2 strings.

    'hallo.null_name.txt' will be split into 'hallo', 'null_name' and 'txt'; the split() returns an array with 3 strings.

    if (File_Extenention.Length > 1)
    {
    }

    If there is more than one element in the array, the file has an extension.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 28, 2014 11:04 AM
  • User2045233432 posted

    thanks wim

    Monday, July 28, 2014 1:26 PM