.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

String Copy, End With and Insert

Posted By:SanthoshNathan       Posted Date: November 01, 2010    Points: 15    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

String Copy, End With and Insert
 

using System;

 namespace StringManipulation
 {
    public class TesterStringCopyEndWithInsert
    {
       public void Run()
       {
           string s1 = "abcd";
           string s2 = "ABCD";
           string s3 = @"Liberty Associates, Inc.
                 provides custom .NET development,
                 on-site Training and Consulting";

           // the string copy method
           string s5 = string.Copy(s2);
           Console.WriteLine(
               "s5 copied from s2: {0}", s5);

           // Two useful properties: the index and the length
           Console.WriteLine(
               "\nString s3 is {0} characters long. ",
               s5.Length);

           Console.WriteLine(
               "The 5th character is {0}\n", s3[4]);

           // test whether a string ends with a set of characters
           Console.WriteLine("s3:{0}\nEnds with Training?: {1}\n",
               s3,
               s3.EndsWith("Training") );
           Console.WriteLine(
               "Ends with Consulting?: {0}",
               s3.EndsWith("Consulting"));

           // return the index of the substring
           Console.WriteLine(
               "\nThe first occurrence of Training ");
           Console.WriteLine ("in s3 is {0}\n",
               s3.IndexOf("Training"));

           // insert the word excellent before "training"
           string s10 = s3.Insert(101,"excellent ");
           Console.WriteLine("s10: {0}\n",s10);

           // you can combine the two as follows:
           string s11 = s3.Insert(s3.IndexOf("Training"),
               "excellent ");
           Console.WriteLine("s11: {0}\n",s11);
       }

       [STAThread]
       static void Main()
       {
          TesterStringCopyEndWithInsert t = new TesterStringCopyEndWithInsert();
          t.Run();
       }
    }
 }


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend