String:
C# string implements 3 interfaces.They are IComparable,IClonable and IConvertible.
The implementation of C# class is shown below.
public sealed class String : IComparable , IClonable , IConvertible
IComparable classes implement the CompareTo( ) method to compare two strings.
IClonable interface implement the clone( ) method to create the same value of string into another string.
IConvertible is used to convert the string into other types like int,double etc.eg: Convert.toint32(string).
String verbatim(@):
Strings can be declared with verbatim symbol so that special characters (for eg: //backslash) are also considered as string.
eg: string test = @ " This is a sample string\\D:\\MyFolder";
Verbatim string helps when in cases like when we are specifying the path.
ToString Method:
Another common way to create a method is to call ToString( ) method on an object an assign it to a string.
eg: int Myinteger = 5;
string Integerstring = Myinteger.ToString( );
String Manipulations:
String Comparison:
When we use string.Compare( ) method , we can compare two strings. The result will be an integer value and is 0 if the two strings are identical and -1 if string1 is smaller than string2 and +1 if the string1 is bigger than string2.Also comparison is case sensitive. So if we want to compare two strings ignoring their case, then we have to declare third parameter in the compare method to "True"
eg: int result = string.Compare(s1, s2, true);
Apart from that there are three methods to check whether string1 is equal to string2.
string.equals(s1,s2);
s1.equals(s2);
s1 = = s2;
LastIndexOf ( ) method
This is used to find the index of the last word in string.
eg: string s = "one two three four";
int x =s.LastIndexOf(" ") // Getting the last word index by deviding with space
Substring( ) Method
Using this we can find whatever words present in a string.
eg: string s1 = s.Substring(x + 1); // will give the result as four .
Split( ) Method
For splitting the strings with delimiters like comma,space etc which is an efficient way of string manipulation,
StringBuilder( ) Method
C# reccomends to use StringBuilder method to improve performance. We can manipulate large strings using stringbuilder. It uses AppendFormat method to append new,formatted strings as you created them.
C# string implements 3 interfaces.They are IComparable,IClonable and IConvertible.
The implementation of C# class is shown below.
public sealed class String : IComparable , IClonable , IConvertible
IComparable classes implement the CompareTo( ) method to compare two strings.
IClonable interface implement the clone( ) method to create the same value of string into another string.
IConvertible is used to convert the string into other types like int,double etc.eg: Convert.toint32(string).
String verbatim(@):
Strings can be declared with verbatim symbol so that special characters (for eg: //backslash) are also considered as string.
eg: string test = @ " This is a sample string\\D:\\MyFolder";
Verbatim string helps when in cases like when we are specifying the path.
ToString Method:
Another common way to create a method is to call ToString( ) method on an object an assign it to a string.
eg: int Myinteger = 5;
string Integerstring = Myinteger.ToString( );
String Manipulations:
String Comparison:
When we use string.Compare( ) method , we can compare two strings. The result will be an integer value and is 0 if the two strings are identical and -1 if string1 is smaller than string2 and +1 if the string1 is bigger than string2.Also comparison is case sensitive. So if we want to compare two strings ignoring their case, then we have to declare third parameter in the compare method to "True"
eg: int result = string.Compare(s1, s2, true);
Apart from that there are three methods to check whether string1 is equal to string2.
string.equals(s1,s2);
s1.equals(s2);
s1 = = s2;
LastIndexOf ( ) method
This is used to find the index of the last word in string.
eg: string s = "one two three four";
int x =s.LastIndexOf(" ") // Getting the last word index by deviding with space
Substring( ) Method
Using this we can find whatever words present in a string.
eg: string s1 = s.Substring(x + 1); // will give the result as four .
Split( ) Method
For splitting the strings with delimiters like comma,space etc which is an efficient way of string manipulation,
StringBuilder( ) Method
C# reccomends to use StringBuilder method to improve performance. We can manipulate large strings using stringbuilder. It uses AppendFormat method to append new,formatted strings as you created them.
No comments:
Post a Comment