JET
TECHNICAL.COM
C Sharp Video Tutorials Online
all skill levels
member news
videos
sample code
C# On Demand!
Using Arrays with the String Split Method
Sometimes you need to get portions of a string. By breaking it apart using a split method,
we can find portions of the string. This can be done using a portion of the string as the delimiter.
Here is a simple piece of code that uses an array and the string split() method to get the values.
This is often used to find if a user entered a valid entry.
First, declare two variables. One holds the value to be checked and the other is the array that will hold the split results of the first value:
private string str = "tamurry@jettechnical.com";// <---holds the string value to be evaluated
private string[] strSplit;// <---array variable that will hold the results of string.split()
strSplit = str.Split('@'); <--split on the at symbol (@)
if(strSplit.GetLength(0) > 0) <--if the length is greater than zero, the @ symbol was found
MessageBox.Show(strSplit[0]);
else
MessageBox.Show(“Invalid email address”);<--no @ symbol means invalid email address.
Need more help on arrays? Start here...Intro to Arrays.
Let us hear your comments,
send us an email.
Members Library
Source Code Downloads
DateTime Functions
Custom Controls
Working with Strings
Working with Text Files
Validating User Input
Free Downloads
Visual Studio Express
Crystal Reports 2008
--MEMBER LOGIN--
email address:
password:
business broker businesses for sale