Argument issues
-
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 exceptionArgument 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 -
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 exceptionArgument 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 argumentWell, 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
-
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
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?? -
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??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
-
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
ThankYou it worked:-D
-
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 exceptionArgument 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 argumentYou 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.
-
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.
At first I though WTF?! Then I tried it... That is just weird. The documentation doesn't say it's right to left...