By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

Splitting a string with VB.Net?

P: 73
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
Jul 9 '08 #1
Share this Question
Share on Google+
1 Reply


Plater
Expert 5K+
P: 7,872
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?
Jul 9 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.