Saturday, 2 April 2016

How To append String in C sharp program

using System;
using System.Text;

public class StringProgram
{
    static void Main()
       {
        StringBuilder sb = new StringBuilder();

        sb.Append("I ").Append("Love ").Append("My... ");

        string built1 = sb.ToString();

        sb.Append("India");

        string built2 = sb.ToString();

        Console.WriteLine( built1 );
        Console.WriteLine( built2 );
    }
}
------------------------------
OUTPUT:-

I Love My...
I Love My... India
-----------------------------------------------------

Friday, 1 April 2016

How to Reading from a string one line at a time in C sharp

public class TopClass
{
    public static void Main()
    {
   
   
        string contents = "My content\r\nHi there";
        using (StringReader reader = new StringReader(contents))
        {
            int lineNo = 0;
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                Console.WriteLine("Line#{0}: {1}", ++lineNo, line);
            }
        }
    }
}
---------------
OUTPUT:-
Line#1: My content
Line#2: Hi there
-----------------------------------