0% found this document useful (0 votes)
40 views

C# String Clone : Public Static Void String String String

The document discusses various string methods in C# including Clone(), Concat(), Contains(), Equals(), GetType(), IsNullOrEmpty(), Split(), ToString(), and Trim(). It provides examples of how to use each method and describes what each method is used for such as cloning a string, concatenating strings, checking if a string contains a substring, comparing string equality, getting the string type, checking if a string is null or empty, splitting a string into substrings, converting types to strings, and removing leading and trailing whitespace from a string.

Uploaded by

champ rider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

C# String Clone : Public Static Void String String String

The document discusses various string methods in C# including Clone(), Concat(), Contains(), Equals(), GetType(), IsNullOrEmpty(), Split(), ToString(), and Trim(). It provides examples of how to use each method and describes what each method is used for such as cloning a string, concatenating strings, checking if a string contains a substring, comparing string equality, getting the string type, checking if a string is null or empty, splitting a string into substrings, converting types to strings, and removing leading and trailing whitespace from a string.

Uploaded by

champ rider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

C# String Clone()

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);  
    }    

You might also like