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

Top 5 Contributors of the Month
Melody Anderson

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);
               "s5 copied from s2: {0}", s5);

           // Two useful properties: the index and the length
               "\nString s3 is {0} characters long. ",

               "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.EndsWith("Training") );
               "Ends with Consulting?: {0}",

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

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

       static void Main()
          TesterStringCopyEndWithInsert t = new TesterStringCopyEndWithInsert();


Further Readings:


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