Hot File

Build C# String Class And Methods

View: 234    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: C / C++ / MFC   Fields: Other

20 point/2 review File has been tested

There are several built-in overloaded methods available inside a string class which helps us to manipulate and working with string objects in several different ways such as join one string to another, search a specific word in string, make a copy of strings etc

Introduction

C# defines a built-in string class which lives inside system namespace such as System.String

String class implements different types of interfaces

It is a sealed class that means we cannot inherit it with other classes

The purpose of string class is that it provides string-handling functionality

There are several built-in overloaded methods available inside a string class which helps us to manipulate and working with string objects in several different ways such as join one string to another, search a specific word in string, make a copy of strings etc

Along with methods the string class also defines a Length property which returns total characters contains a specific string.

Some String Class Methods:

Example – 1, Use of PadRight() method:

using System;
namespace csharpAdvance
{
    class Program
    {
        static void Main(string[] args)
        {
            // A string initialization.
            string siteName = "Tutorialstown";
 
            // PadRight() method is called and displayed.
            Console.Write(siteName.PadRight(22, '*'));
            Console.ReadKey();
        }
    }
    /*  The Output will be:
      
        Tutorialstown*********
     */
}

Example – 2, Use of StartsWith() method:

using System;
namespace csharpAdvance
{
    class Program
    {
        static void Main(string[] args)
        {
            // A string initialization.
            string siteName = "Tutorialstown";
 
            if (siteName.StartsWith("tutorialstown",true, System.Globalization.CultureInfo.CurrentCulture))
                Console.WriteLine("Yes, it is a tutorialstown.com");
            else
                Console.WriteLine("No, it is not a tutorialstown.com");
 
            Console.ReadKey();
        }
    }
    /*  The Output will be:
      
        Yes, it is a tutorialstown.com
     */
}

Example – 3, Use of trim() method:

using System;
namespace csharpAdvance
{
    class Program
    {
        static void Main(string[] args)
        {
            // A string initialization.
            string siteName = "\t\t\tTutorialstown";
 
            Console.WriteLine("Before trim() method:");
            Console.WriteLine(siteName);
 
            Console.WriteLine("After trim() method:");
            Console.WriteLine(siteName.Trim());
 
            Console.ReadKey();
        }
    }
    /*  The Output will be:
      
        Before trim() method:
                               Tutorialstown
        After trim() method:
        Tutorialstown
 
     */
}

Example – 4, Use of Length property:

using System;
namespace csharpAdvance
{
    class Program
    {
        static void Main(string[] args)
        {
            // A string initialization.
            string siteName = "Tutorialstown";
 
            Console.WriteLine("Total characters are: {0}", siteName.Length);
            Console.ReadKey();
        }
    }
    /*  The Output will be:
      
        Total characters are: 13
     */
}

Example – 5, Use of ToCharArray() method:

using System;
namespace csharpAdvance
{
    class Program
    {
        static void Main(string[] args)
        {
            // A string initialization.
            string siteName = "Tutorialstown";
 
            // ToCharArray() method converts string into an character array.
            char[] charArray = siteName.ToCharArray();
 
            // Loop throug each element from char array and displayed.
            for (int index = 0; index < charArray.Length; index++)
 
                Console.WriteLine(index + " - " + charArray[index]);
 
            Console.ReadKey();
        }
    }
    /*  The Output will be:
      
        0 - T
        1 - u
        2 - t
        3 - o
        4 - r
        5 - i
        6 - a
        7 - l
        8 - s
        9 - t
        10 - o
        11 - w
        12 - n
 
     */
}

Build C# String Class And Methods

Build C# String Class And Methods Posted on 06-09-2016  There are several built-in overloaded methods available inside a string class which helps us to manipulate and working with string objects in several different ways such as join one string to another, search a specific word in string, make a copy of strings etc 10/10 234

Comment:

To comment you must be logged in members.

Files with category

  • How to Swap Two Numbers using Call by Reference in C

    View: 404    Download: 0   Comment: 0   Author: none  

    How to Swap Two Numbers using Call by Reference in C

    Category: C / C++ / MFC
    Fields: Other

    0/0 review
    How to swap two numbers using call by reference in C , C++. In the interviews interviewer generally asked the difference between call by reference and call by value

  • How to Print Fibonacci Series using Recursion in C, C++

    View: 411    Download: 0   Comment: 0   Author: none  

    How to Print Fibonacci Series using Recursion in C, C++

    Category: C / C++ / MFC
    Fields: Other

    4.5/1 review
    Write a program to print Fibonacci Series using recursion. Fibonacci series is a very important program in terms of interviews. To make this program little tough interviewer ask to write a fibonacci series code using recursion.

  • How to Implicitly Typed Arrays In C#

    View: 452    Download: 0   Comment: 0   Author: none  

    How to Implicitly Typed Arrays In C#

    Category: C / C++ / MFC
    Fields: Other

    0/1 review
    When we initialize these type of arrays with any data type, the compiler convert these arrays into that data type at compile time.

  • How to C# Static vs Instance Methods As Event Handlers

    View: 308    Download: 0   Comment: 0   Author: none  

    How to C# Static vs Instance Methods As Event Handlers

    Category: C / C++ / MFC
    Fields: Other

    0/0 review
    Both static and instance methods can be used as event handlers in C#

  • Build Pass By Reference To Method In C#

    View: 465    Download: 0   Comment: 0   Author: none  

    Build Pass By Reference To Method In C#

    Category: C / C++ / MFC
    Fields: Other

    0/3 review
    Like value types such as int, double, char etc. We can also pass a reference variable to the method in C# as its parameter which allows us to pass an object to the method and it is called pass by reference to method in C#.

  • How to C# Continue Statement

    View: 294    Download: 0   Comment: 0   Author: none  

    How to C# Continue Statement

    Category: C / C++ / MFC
    Fields: Other

    0/2 review
    continue statement skips or exits the current execution of a loop by given condition and keep execution continue for its next iteration unlike break statement it does not exit or terminate from loops, it terminates only its current execution

  • How to Single Dimensional Arrays In C#

    View: 238    Download: 0   Comment: 0   Author: none  

    How to Single Dimensional Arrays In C#

    Category: C / C++ / MFC
    Fields: Other

    0/1 review
    Single Dimensional Arrays in C# store each individual element at their single dimension, position or a specific location, that location is called an array index. Each index describes the position of each element within an array. Each element in an...

  • Build C# Multilevel Inheritance

    View: 259    Download: 0   Comment: 0   Author: none  

    Build C# Multilevel Inheritance

    Category: C / C++ / MFC
    Fields: Other

    2.5/2 review
    C# supports multilevel inheritance, suppose we have four classes A, B, C and D. Class A can inherit to B, B to C and C can inherit to D and so on now class D has all public members of class A, B and C include its own.

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd