C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




what is split() function


Posted Date: 30 Jul 2008      Total Responses: 11

Posted By: biswa       Member Level: Gold     Points: 1



can any body tell where we use split function with a small examle.




Responses

Author: chandramohan    30 Jul 2008Member Level: GoldRating:     Points: 1

The Split function returns a zero-based, one-dimensional array that contains a specified number of substrings

dim txt,a
txt="Hello World!"
a=Split(txt)
document.write(a(0) & "<br />")
document.write(a(1))Output:Hello
World!




Author: suman    30 Jul 2008Member Level: GoldRating:     Points: 4

String.split()
This method finds all the substrings in a string that are seperated by one or more characters

Dim str As String = "welcome,hi,hello"

For Each s As String In str.Split(",")
Response.Write(s & "<br>")
Next

Output:

Welcome
Hi
hello



Author: chandramohan    30 Jul 2008Member Level: GoldRating:     Points: 1

What's the Split?
Let's look at the function itself. The Split function, according to the documentation, "returns a zero based, one-dimensional array containing a specified number of substrings." Yes, I can hear the groans; "oh no, not another array function. I don't use no stinkin' arrays in my code anyway!"

Don't give up yet. There is hope. The Split function is defined by this syntax:



Split(expression [, delimiter [, count [, compare]]])

This is how it is explained:


The function name is Split, and yes, it is a function, so it needs to be on the right hand side of an equal-to sign.
"Expression" is a required string expression containing substrings and delimiters.
"Delimiter" is an optional string identifying the delimiter character. By default, a space character (" ") is considered to be the delimiter.
"Count" is an optional number of substrings to return. The default is -1, which indicates all substrings are to be returned.
"Compare" is an optional numeric value signifying how the comparison should take place for evaluating substrings. A 0 indicates binary comparison; a 1 (the default) signifies textual comparison.
Given a text string, the Split function can quickly and efficiently break it down into an array of strings, based on your chosen delimiter. So, if you had the following string:



"This is the tactical ASP column by Rama Ramachandran"

the following code breaks the string into an array of strings, each containing one word.



Dim strAryWords
Dim strValue

strValue = "This is the tactical ASP column by Rama Ramachandran"
strAryWords = Split(strValue, " ")
' - strAryWords is now an array
Dim i
For i = 0 to Ubound(strAryWords)
Response.Write i & " = " & strAryWords(i) & "<BR>"
Next

The above code will produce the following output:



0 = This
1 = is
2 = the
3 = tactical
4 = ASP
5 = column
6 = by
7 = Rama
8 = Ramachandran




Author: Tanuja    30 Jul 2008Member Level: GoldRating:     Points: 3

When u want to split a string then we use split() function.
Example:
String str = "abc-def";
String[] strsplit = str.split('-');
Here strsplit[0] has abc and
strsplit[1] has def




Author: chandramohan    30 Jul 2008Member Level: GoldRating:     Points: 1

JavaScript String Split Function
The ability to split up a string into separate chunks has been supported in many programming languages, and it is available in JavaScript as well. If you have a long string like "Bobby Susan Tracy Jack Phil Yannis" and want to store each name separately, you can specify the space character " " and have the split function create a new chunk every time it sees a space

Split Function: Delimiter
The space character " " we mentioned will be our delimiter and it is used by the split function as a way of breaking up the string. Every time it sees the delimiter we specified, it will create a new element in an array. The first argument of the split function is the delimiter.

Simple Split Function Example
Let's start off with a little example that takes a string of numbers and splits when it sees the number 5. That means the delimiter for this example is 5. Notice that the split function returns an array that we store into mySplitResult.

JavaScript Code:
<script type="text/javascript">
var myString = "123456789";

var mySplitResult = myString.split("5");

document.write("The first element is " + mySplitResult[0]);
document.write("<br /> The second element is " + mySplitResult[1]);
</script>

Display:
The first element is 1234
The second element is 6789
Make sure you realize that because we chose the 5 to be our delimiter, it is not in our result. This is because the delimiter is removed from the string and the remaining characters are separated by the chasm of space that the 5 used to occupy.

Larger Split Function Example
Below we have created a split example to illustrate how this function works with many splits. We have created a string with numbered words zero through four. The delimiter in this example will be the space character " ".

JavaScript Code:
<script type="text/javascript">
var myString = "zero one two three four";

var mySplitResult = myString.split(" ");

for(i = 0; i < mySplitResult.length; i++){
document.write("<br /> Element " + i + " = " + mySplitResult[i]);
}
</script>

Display:

Element 0 = zero
Element 1 = one
Element 2 = two
Element 3 = three
Element 4 = four



Author: akhilesh chauhan    30 Jul 2008Member Level: GoldRating:     Points: 6

Split string function provides the functionality to split the string into a string array by specifying its delimiters.

C# split string function splits the string into array collection according to the number of separators passed to the split function.

ASP.Net C# split string function removes the delimiters from the string and stores each part separated at consecutive indexes of array object.

e.g.

string s = "One Two Three Four";
string[] strArray;
char[] saperator = { ' ' };
strArray = s.Split(saperator);

will create four elements in atrArray. with the values "One", "Two", "Three" and "Four" respectively...



Author: UltimateRengan    30 Jul 2008Member Level: DiamondRating:     Points: 1

C# code for doing a simple split. There's probably a simpler way to do this but I haven't discovered it yet.

using System.Text.RegularExpressions;

public string[] split(string sData, string sToken)
{
Regex r = new Regex("(" + sToken + ")");
string[] s = r.Split(sData);

int iHalf = System.Convert.ToInt16((s.GetUpperBound(0) / 2) + 1);
string[] res = new string[iHalf];

int j = 0;
for (int i=0; i <= s.GetUpperBound(0); i++)
{
if (s[i] != sToken)
{
res[j] = s[i];
j++;
}
}
return res;
}



UltimateRengan
nathan.rengan@gmail.com
Trichy-Rider Group



Author: Senthil V    30 Jul 2008Member Level: GoldRating:     Points: 4

Hi,

Returns a zero-based, one-dimensional array containing a specified number of substrings.

Dim strSplit As String = "Hello, welcome, to, india"

For Each str As String In strSplit.Split(",")

Response.Write(str & "<br>")

Next

Output:

Hello
welcome
to
india

Hi
hello



Author: Raghuramakarthikeyan    30 Jul 2008Member Level: GoldRating:     Points: 2

Hai Biswa,

Example For Split:

String a=10.234;
String[] b = new String[10];

b=a.Split('.');
b[0]=10;
b[1]=234;

This May Help You



Author: Ratheesh    30 Jul 2008Member Level: GoldRating:     Points: 1

The split() function has many uses in Perl. Its main purpose is to take a string and break it apart, returning a list of strings. In our first example, we will take a sentence and break each word into a list. Here it is in code:




#!/usr/bin/perl

$Trees = "Why aren't there any fat trees? All they do is eat all day

and sit around.\n\n";

@Pieces = split(/ /, $Trees);

print $Trees;

print @Pieces;

This code takes each word in the $Trees string and puts each one as an element in the @Pieces list. The split() function above has the following as its argument: (/ /, $Trees). The first part, “/ /” is two forward slashes with a space between them. Whatever you place in between the forward slashes is used as a delimiter. So in this instance, split() looks at the $Trees variable, finds the first word, sees a space, then adds that word to the @Pieces first element. Next it sees the next word, finds a space after it, and adds that word as the second element



Author: chandramohan    01 Aug 2008Member Level: GoldRating:     Points: 1

string s = "One Two Three Four";
string[] strArray;
char[] saperator = { ' ' };
strArray = s.Split(saperator);




Post Reply
You must Sign In to post a response.
Next : databinding
Previous : checkboxes in a gridview
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use