C# String Clone : Public Static Void String String String
C# String Clone : Public Static Void String String String
The C# Clone() method is used to clone a string object. It returns another copy of same data.
The return type of Clone() method is object.
public static void Main(string[] args)
{
string s1 = "Hello ";
string s2 = (String)s1.Clone();
Console.WriteLine(s1);
Console.WriteLine(s2);
}
C# String Concat()
The C# Concat() method is used to concatenate multiple string objects. It returns
concatenated string. There are many overloaded methods of Concat().
public static void Main(string[] args)
{
string s1 = "Hello ";
string s2 = "C#";
Console.WriteLine(string.Concat(s1,s2));
}
C# String Contains()
The C# Contains() method is used to return a value indicating whether the specified substring
occurs within this string or not. If the specified substring is found in this string, it returns true
otherwise false.
public static void Main(string[] args)
{
string s1 = "Hello ";
string s2 = "He";
string s3 = "Hi";
Console.WriteLine(s1.Contains(s2));
Console.WriteLine(s1.Contains(s3));
}
C# String Equals()
The C# Equals() method is used to check whether two specified String objects have the same
value or not. If both strings have same value, it return true otherwise false.
public static void Main(string[] args)
{
string s1 = "Hello";
string s2 = "Hello";
string s3 = "Bye";
Console.WriteLine(s1.Equals(s2));
Console.WriteLine(s1.Equals(s3));
}
C# String GetType()
The C# GetType() method is used to get type of current object. It returns the instance of Type
class which is used for reflection.
public static void Main(string[] args)
{
string s1 = "Hello C#";
Console.WriteLine(s1.GetType());
}
C# String IsNullOrEmpty()
The C# IsNullOrEmpty() method is used to check whether the specified string is null or an
Empty string. It returns a boolean value either true or false.
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = "";
bool b1 = string.IsNullOrEmpty(s1);
bool b2 = string.IsNullOrEmpty(s2);
Console.WriteLine(b1);
Console.WriteLine(b2);
}
C# String Split()
The C# Split() method is used to split a string into substrings on the basis of characters in an
array. It returns string array.
public static void Main(string[] args)
{
string s1 = "Hello C Sharp";
string[] s2 = s1.Split(' ');
foreach (string s3 in s2)
{
Console.WriteLine(s3);
}
}
C# String ToString()
The C# ToString() method is used to get instance of String.
public static void Main(string[] args)
{
string s1 = "Hello C#";
int a = 123;
string s2 = s1.ToString();
string s3 = a.ToString();
Console.WriteLine(s2);
Console.WriteLine(s3);
}
C# String Trim()
The C# Trim() method is used to remove all leading and trailing white-space characters from
the current String object.
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = s1.Trim();
Console.WriteLine(s2);
}