Overview:
In this article i would like to publish Split Method with an "@" Identifier using C#.Net.Related to String related articles you can visit the link.
Description:
String is a collection of characters it can be used as a string data type as well as string class.When string acts as a class it consists of split method.
Split:
String class consists of split method it is used to split a data as per the usage of delimiters used by a users.It identifies the substrings that are delimited by one or more characters specified in an array, and then return these substrings in a string array.
Forms of a Split Method:
we want to split a given string "Naga Veerendra Parvataneni".Here we use " "(space) as a delimiter like wise we can split a given strings.
In this section i would like to explore different ways of splitting a given string with the usage of an "@" Identifier.
Don't use unrecognized delimiters in split array.Like "\N" is Different from "\n".If you use that it gives an error.It Can be Possible only if you use "@" preceded of the string.For Example U can visit.
About an Identifier "@":
When the at sign (@) occurs before an identifier—the name of a method, property, variable, …—, then the compiler will consider the following string to be an identifier even if the string already has a meaning, e.g. a keyword.
E.g:
int new=100;//new is a keyword it gives an error if we use that statement.
int @new=100;//it won't gives an error because compiler can be used as an identifier even it already have a meaning.
Program:
In this article i would like to publish Split Method with an "@" Identifier using C#.Net.Related to String related articles you can visit the link.
Description:
String is a collection of characters it can be used as a string data type as well as string class.When string acts as a class it consists of split method.
Split:
String class consists of split method it is used to split a data as per the usage of delimiters used by a users.It identifies the substrings that are delimited by one or more characters specified in an array, and then return these substrings in a string array.
Forms of a Split Method:
- string[] Split(params char[])
- string[] Split(params char[] separator)
we want to split a given string "Naga Veerendra Parvataneni".Here we use " "(space) as a delimiter like wise we can split a given strings.
In this section i would like to explore different ways of splitting a given string with the usage of an "@" Identifier.
Don't use unrecognized delimiters in split array.Like "\N" is Different from "\n".If you use that it gives an error.It Can be Possible only if you use "@" preceded of the string.For Example U can visit.
About an Identifier "@":
When the at sign (@) occurs before an identifier—the name of a method, property, variable, …—, then the compiler will consider the following string to be an identifier even if the string already has a meaning, e.g. a keyword.
E.g:
int new=100;//new is a keyword it gives an error if we use that statement.
int @new=100;//it won't gives an error because compiler can be used as an identifier even it already have a meaning.
Program:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
split123
{
class Class3
{
static void Main(string[]
args)
{
string
s=@"Hi\Nhow r u\NWelcome to This \NBlog share\NYour
Ideas........\NUr'sVeerendra... ";
string[]
a;
Console.WriteLine("Original String");
Console.WriteLine(s);
Console.WriteLine("*********************************************");
Console.WriteLine("After Splitting");
string[]
b = new string[]
{ @"\N" };
a = s.Split(b,StringSplitOptions.None);
foreach
(string p in a)
{
Console.WriteLine(p);
}
Console.ReadLine();
}
}
}
Output:
No comments:
Post a Comment