I am getting a string from a user and Would like to split the Data base on certain cinditions, I know how to split the sting with an Array and the Split method. I am fine if the user has put that string in correctly but if they use a different delimeter then the code does not pick that up just ignores any splitting and goes on with the program and the whole string instead of what I wanted.How can I force the Program to break if the string can't be split so that i can get and error message for this. My code is already in a try catch block and even when I do try to force the break the code seems to side step somthing. Any Help will be Appreciated thank
Splitting a string with VB.Net?
Collapse
X
-
Well the .Split() method returns an array.
Simply look at the size of the array, if there are not X pieces (where X is the amount you need to be 'correctly split') then throw a new exception to trigger your try/catch blocks.
Or do a check with .IndexOf() or .Contains() to see if your delimeter is even in the string in the first place?
Comment