Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Argument issues

Argument issues

Scheduled Pinned Locked Moved C#
data-structures
7 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saira Tanwir
    wrote on last edited by
    #1

    Oh Brainy Ones! final_list=Convert.ToString(attribute_list.LastIndexOf(",",1,attribute_list.Length)); All it returns is -1. If I change the value of the third argument of the function to 1,it returns -1. The above code gives an exception Argument Out of Range exception. Count must be positive and count must refer to a location within the string/array/collection. i.e. count is the third argument

    C K 2 Replies Last reply
    0
    • S Saira Tanwir

      Oh Brainy Ones! final_list=Convert.ToString(attribute_list.LastIndexOf(",",1,attribute_list.Length)); All it returns is -1. If I change the value of the third argument of the function to 1,it returns -1. The above code gives an exception Argument Out of Range exception. Count must be positive and count must refer to a location within the string/array/collection. i.e. count is the third argument

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well, it's hard to comment without knowing what is in attribute_list.  It seems it doesn't contain a ,, and so the index is -1 ( indicating failure ).

      Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

      S 1 Reply Last reply
      0
      • C Christian Graus

        Well, it's hard to comment without knowing what is in attribute_list.  It seems it doesn't contain a ,, and so the index is -1 ( indicating failure ).

        Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

        S Offline
        S Offline
        Saira Tanwir
        wrote on last edited by
        #3

        i've checked the string and it does contain a ",", but the third argument of the LastIndexOf() still gives the exception. Count must be positive and count must refer to a location within the string/array/collection. the only time it doesn't give the exception is when v give 1 in its third argument. any other suggestions??

        C 1 Reply Last reply
        0
        • S Saira Tanwir

          i've checked the string and it does contain a ",", but the third argument of the LastIndexOf() still gives the exception. Count must be positive and count must refer to a location within the string/array/collection. the only time it doesn't give the exception is when v give 1 in its third argument. any other suggestions??

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          First suggestion : use ToString instead of Convert.ToString Second suggestion: change the 1 to 0, strings are 0 based.  This means when you start with 1, the Length property is 1 bigger than what is allowable, hence the exception. Third suggestion: if you want to search the entire string, don't specify a start and length at all, you can just give it the ',', and it will search the entire string.

          Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

          S 1 Reply Last reply
          0
          • C Christian Graus

            First suggestion : use ToString instead of Convert.ToString Second suggestion: change the 1 to 0, strings are 0 based.  This means when you start with 1, the Length property is 1 bigger than what is allowable, hence the exception. Third suggestion: if you want to search the entire string, don't specify a start and length at all, you can just give it the ',', and it will search the entire string.

            Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

            S Offline
            S Offline
            Saira Tanwir
            wrote on last edited by
            #5

            ThankYou it worked:-D

            1 Reply Last reply
            0
            • S Saira Tanwir

              Oh Brainy Ones! final_list=Convert.ToString(attribute_list.LastIndexOf(",",1,attribute_list.Length)); All it returns is -1. If I change the value of the third argument of the function to 1,it returns -1. The above code gives an exception Argument Out of Range exception. Count must be positive and count must refer to a location within the string/array/collection. i.e. count is the third argument

              K Offline
              K Offline
              Karthik Kalyanasundaram
              wrote on last edited by
              #6

              You need to use, int index = attribute_List.LastIndexOf(",",attribute_List.Length - 1,attribute_List.Length); Reason: LastIndexOf() method searches for the given string from right to left, so you need to specify the second parameter, ie. the startIndex from right to left. Hope the thing is clear.

              B 1 Reply Last reply
              0
              • K Karthik Kalyanasundaram

                You need to use, int index = attribute_List.LastIndexOf(",",attribute_List.Length - 1,attribute_List.Length); Reason: LastIndexOf() method searches for the given string from right to left, so you need to specify the second parameter, ie. the startIndex from right to left. Hope the thing is clear.

                B Offline
                B Offline
                bobsugar222
                wrote on last edited by
                #7

                At first I though WTF?! Then I tried it... That is just weird. The documentation doesn't say it's right to left...

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups