{
class Program
{
static void Main(string[] args)
{
string message = "I have to 2 hands.";
Console.WriteLine(message.Length);
Console.WriteLine(message.Contains ("have"));
Console.WriteLine(message.EndsWith(";"));
Console.WriteLine(message.IndexOf("I"));
Console.WriteLine(message.Insert(1, " hi"));
Console.WriteLine(message.LastIndexOf('a'));
Console.WriteLine(message.Remove(5,4));
Console.WriteLine(message.Replace("e", "i"));
Console.WriteLine(message.StartsWith("i"));
Console.WriteLine(message.Substring(4,2));
Console.WriteLine(message.ToUpper());
Console.WriteLine(message.ToLower());
Console.WriteLine(" dsadwq ewq ".Trim());
Console.WriteLine(" dsadwq ewq ".TrimEnd());
Console.WriteLine(" dsadwq ewq ".TrimStart());
Console.ReadLine();
}
}
}
Miyerkules, Enero 11, 2012
C# ConApp 9: Count 1 to 100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 101; i++)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 101; i++)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
}
}
C# ConApp 8 : Identifier
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a string:");
string input = Console.ReadLine();
int lettercounter = 0;
int digitcounter = 0;
int spacecounter = 0;
int punctuationcounter = 0;
for (int index = 0; index < input.Length; index++)
{
if (char.IsLetter(input, index))
{
lettercounter++;
}
else
if (char.IsDigit(input, index))
{
digitcounter++;
}
else
if (char.IsWhiteSpace(input, index))
{
spacecounter++;
}
else
if (char.IsPunctuation(input, index))
{
punctuationcounter++;
}
}
Console.WriteLine("punction : " + punctuationcounter);
Console.WriteLine("space : " + spacecounter);
Console.WriteLine("digit : " + digitcounter);
Console.WriteLine("letter : " + lettercounter);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a string:");
string input = Console.ReadLine();
int lettercounter = 0;
int digitcounter = 0;
int spacecounter = 0;
int punctuationcounter = 0;
for (int index = 0; index < input.Length; index++)
{
if (char.IsLetter(input, index))
{
lettercounter++;
}
else
if (char.IsDigit(input, index))
{
digitcounter++;
}
else
if (char.IsWhiteSpace(input, index))
{
spacecounter++;
}
else
if (char.IsPunctuation(input, index))
{
punctuationcounter++;
}
}
Console.WriteLine("punction : " + punctuationcounter);
Console.WriteLine("space : " + spacecounter);
Console.WriteLine("digit : " + digitcounter);
Console.WriteLine("letter : " + lettercounter);
Console.ReadLine();
}
}
}
C# ConApp 7 : Flames
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter male name: ");
string male = Console.ReadLine();
Console.Write("Enter female name: ");
string female = Console.ReadLine();
string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
int maletotal = 0;
int femaletotal = 0;
for (int index = 0; index < alphabets.Length; index++)
{
int malecount = 0;
for (int maleindex = 0; maleindex < male.Length; maleindex++)
{
if (char.Parse(male.Substring(maleindex, 1).ToUpper()) ==
char.Parse(alphabets.Substring(index, 1)))
malecount++;
}
int femalecount = 0;
for (int femaleindex = 0; femaleindex < female.Length; femaleindex++)
{
if (char.Parse(female.Substring(femaleindex, 1).ToUpper()) ==
char.Parse(alphabets.Substring(index, 1)))
femalecount++;
}
if (malecount > 0 && femalecount > 0)
{
maletotal += malecount;
femaletotal += femalecount;
}
}
switch ((maletotal + femaletotal) % 6)
{
case 0:
Console.WriteLine("Sweetheart");
break;
case 1:
Console.WriteLine("friend");
break;
case 2:
Console.WriteLine("Lovers");
break;
case 3:
Console.WriteLine("Angry");
break;
case 4:
Console.WriteLine("Married");
break;
case 5:
Console.WriteLine("Engaged");
break;
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter male name: ");
string male = Console.ReadLine();
Console.Write("Enter female name: ");
string female = Console.ReadLine();
string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
int maletotal = 0;
int femaletotal = 0;
for (int index = 0; index < alphabets.Length; index++)
{
int malecount = 0;
for (int maleindex = 0; maleindex < male.Length; maleindex++)
{
if (char.Parse(male.Substring(maleindex, 1).ToUpper()) ==
char.Parse(alphabets.Substring(index, 1)))
malecount++;
}
int femalecount = 0;
for (int femaleindex = 0; femaleindex < female.Length; femaleindex++)
{
if (char.Parse(female.Substring(femaleindex, 1).ToUpper()) ==
char.Parse(alphabets.Substring(index, 1)))
femalecount++;
}
if (malecount > 0 && femalecount > 0)
{
maletotal += malecount;
femaletotal += femalecount;
}
}
switch ((maletotal + femaletotal) % 6)
{
case 0:
Console.WriteLine("Sweetheart");
break;
case 1:
Console.WriteLine("friend");
break;
case 2:
Console.WriteLine("Lovers");
break;
case 3:
Console.WriteLine("Angry");
break;
case 4:
Console.WriteLine("Married");
break;
case 5:
Console.WriteLine("Engaged");
break;
}
Console.ReadLine();
}
}
}
C# ConApp 6: count the word in the message
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(" enter a message ");
string message = Console.ReadLine();
Console.Write(" enter a word ");
string word = Console.ReadLine();
int wordcount = 0;
int index = 0;
while (message.IndexOf(word, index) >= 0)
{
wordcount++;
index = message.IndexOf(word, index) + word.Length;
}
Console.WriteLine("number of words : " + wordcount);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(" enter a message ");
string message = Console.ReadLine();
Console.Write(" enter a word ");
string word = Console.ReadLine();
int wordcount = 0;
int index = 0;
while (message.IndexOf(word, index) >= 0)
{
wordcount++;
index = message.IndexOf(word, index) + word.Length;
}
Console.WriteLine("number of words : " + wordcount);
Console.ReadLine();
}
}
}
C# ConApp 5: Short Encryption
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(" enter a message ");
string message = Console.ReadLine();
Console.Write("Enter shift code: ");
int code = int.Parse(Console.ReadLine());
string alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
string encrypted = "";
for (int index = 0; index < message.Length; index++)
{
if (char.IsUpper(message, index))
encrypted +=
alphabet.Substring((alphabet.IndexOf(message.Substring(index, 1)) + code) % 26, 1);
else
{
if (char.IsLower(message, index))
encrypted +=
alphabet.ToLower().Substring(
(alphabet.ToLower().IndexOf(
message.Substring(index, 1))
+ code) % 26, 1);
}
}
Console.WriteLine("Encrypted :" + encrypted);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(" enter a message ");
string message = Console.ReadLine();
Console.Write("Enter shift code: ");
int code = int.Parse(Console.ReadLine());
string alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
string encrypted = "";
for (int index = 0; index < message.Length; index++)
{
if (char.IsUpper(message, index))
encrypted +=
alphabet.Substring((alphabet.IndexOf(message.Substring(index, 1)) + code) % 26, 1);
else
{
if (char.IsLower(message, index))
encrypted +=
alphabet.ToLower().Substring(
(alphabet.ToLower().IndexOf(
message.Substring(index, 1))
+ code) % 26, 1);
}
}
Console.WriteLine("Encrypted :" + encrypted);
Console.ReadLine();
}
}
}
C# ConApp 4: Encryption
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(" enter a message ");
string message = Console.ReadLine();
Console.Write("Enter shift code: ");
int code = int.Parse(Console.ReadLine());
string alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
string encrypted = "";
for (int index = 0; index < message.Length; index++)
{
if (char.IsUpper(message, index))
encrypted +=
alphabet.Substring((alphabet.IndexOf(message.Substring(index, 1)) + code) % 26, 1);
else
{
if (char.IsLower(message, index))
encrypted +=
alphabet.ToLower().Substring(
(alphabet.ToLower().IndexOf(
message.Substring(index, 1))
+ code) % 26, 1);
}
}
Console.WriteLine("Encrypted :" + encrypted);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(" enter a message ");
string message = Console.ReadLine();
Console.Write("Enter shift code: ");
int code = int.Parse(Console.ReadLine());
string alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
string encrypted = "";
for (int index = 0; index < message.Length; index++)
{
if (char.IsUpper(message, index))
encrypted +=
alphabet.Substring((alphabet.IndexOf(message.Substring(index, 1)) + code) % 26, 1);
else
{
if (char.IsLower(message, index))
encrypted +=
alphabet.ToLower().Substring(
(alphabet.ToLower().IndexOf(
message.Substring(index, 1))
+ code) % 26, 1);
}
}
Console.WriteLine("Encrypted :" + encrypted);
Console.ReadLine();
}
}
}
C# ConApp 3: Jagged Array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[][] jagged = new int[3][];
jagged[0] = new int[2] { 9, 8 };
jagged[1] = new int[3] { 0, 3, 5 };
jagged[2] = new int[1] { 1 };
for (int row = 0; row < jagged.Length; row++)
{
for (int element = 0; element < jagged[row].Length; element++)
{
Console.WriteLine("row: {0}, element: {1}, value: {2}", row, element, jagged[row][element]);
}
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[][] jagged = new int[3][];
jagged[0] = new int[2] { 9, 8 };
jagged[1] = new int[3] { 0, 3, 5 };
jagged[2] = new int[1] { 1 };
for (int row = 0; row < jagged.Length; row++)
{
for (int element = 0; element < jagged[row].Length; element++)
{
Console.WriteLine("row: {0}, element: {1}, value: {2}", row, element, jagged[row][element]);
}
}
Console.ReadLine();
}
}
}
C# ConApp 2: Multi Array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] twodim = new int[3, 3];
int[, ,] threedim = {
{{1,2}, {3,4}},
{{4,6}, {7,8}},
{{9,10}, {11,12}}
};
Console.WriteLine (threedim [0,1,1]);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] twodim = new int[3, 3];
int[, ,] threedim = {
{{1,2}, {3,4}},
{{4,6}, {7,8}},
{{9,10}, {11,12}}
};
Console.WriteLine (threedim [0,1,1]);
Console.ReadLine();
}
}
}
C# ConApp: 1 Array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] ArrayDaw = new int[4] { 1, 2, 3, 4 };
string[] Waah = { "bandolp", "jenny", "phoppy","nico","daffy" };
foreach (string val in Waah)
{
Console.WriteLine(val );
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] ArrayDaw = new int[4] { 1, 2, 3, 4 };
string[] Waah = { "bandolp", "jenny", "phoppy","nico","daffy" };
foreach (string val in Waah)
{
Console.WriteLine(val );
}
Console.ReadLine();
}
}
}
Mag-subscribe sa:
Mga Post (Atom)