C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 10 November 2013

Some String Concepts


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace stringss
{
    class Program
    {
        static void Main(string[] args)
        {

            string a1 = "wow what a idea man";//wow what a idea man
            string a2 = @"wow what a idea man";//wow what a idea man
            string a3 = "wow what a \t man";//wow what a     idea man
            string a4="wow what a \"idea\" man";//wow what a "idea" man
            string a5 = @"wow what a ""idea"" man";//wow what a "idea" man
            string a6 = "wow what an \n idea man";//new lines inserted
            string a7 = "wow what a \r idea man"; //doubt check it out man


            Console.WriteLine(a1);
            Console.WriteLine(a2);
            Console.WriteLine(a3);
            Console.WriteLine(a4);
            Console.WriteLine(a5);
            Console.WriteLine(a6);
            Console.WriteLine(a7);
            Console.ReadLine();
        }
    }
}

-------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    

    class Program
    {
        static void Main()
        {   
            string s1 = "strings2";
            string s3 = "string2f";
            int a= string.Compare(s1, s3);
            Console.WriteLine(a);
            s1 = string.Empty;
            Console.WriteLine(s1);
            Console.ReadLine();
        }
    }

}

output is: 1

Note :
1 [If Two strings are unequal]
0 [If Two Strings are Equal]

-------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

    class Sample
    {
        public static void Main()
        {
            String[] val = { "apple", "orange", "grape", "pear" };
            String sep = " # ";
            String result;

            Console.WriteLine("sep = '{0}'", sep);
            Console.WriteLine("val[] = {{'{0}' '{1}' '{2}' '{3}'}}", val[0], val[1], val[2], val[3]);
            result = String.Join(sep, val, 1, 3);
            Console.WriteLine("String.Join(sep, val, 1, 3) = '{0}'", result);
            Console.ReadLine();
        }
    }

}

we get the output as follows....
This example produces the following results:
sep = ', '
val[] = {'apple' 'orange' 'grape' 'pear'}
String.Join(sep, val, 1, 3) = 'orange # grape # pear'

-----------------
using System;

class Program
{
    static void Main()
    {

string s1 = "string2";
string s2 = "string1" + s1;
Console.WriteLine(s2);
    }
}

Output

string1string2
-------------------
using System;

class Program
{
    static void Main()
    {
string s1 = "string2";
string s2 = string.Concat("string1", s1);
Console.WriteLine(s2);
    }
}

Output

string1string2
---------------------------string verbatim---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           Console.WriteLine(@"anurag
is a good boy
             ");
            Console.ReadLine();
        }
    }
}

O/p:
anurag
is a good boy

No comments:

Post a Comment