Checking if a string(1) is empty or notthe

DevilCult

New member
Joined
Mar 22, 2013
Messages
1
Programming Experience
Beginner
Hello i'm having some difficulty with this problem. I'm getting a list of word from a textbox wich look like this: Whatever#2, word, is, there
Then im splitting up that line with the , identifier and put it in a array lets say x(). Now i have another array named y() which gonna resplit each word with the identifier "#"
so in the final i have an array named y(0) which contain the word and sometime y(1) which contain a number. But when i try to check with an if statement if y(1) is nothing i get an IndexOutofRangeException because there is nothing in it... I know there is nothing but how to check it in code please? I'm confused.

Thanks for reply! :)
 
There's no point checking for Nothing because it can't possibly be Nothing. If there is a # in the initial value then the resulting array will have two elements and the second element will be an empty String. If there is no # in the initial value then the resulting array will only have one element. That's why you get an IndexOutOfRangeException: there is no element at index 1. So, first you need to test the length of the array and, if there is a second element, test whether it is an empty String.
 
Back
Top