{
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();
}
}
}
ProjectKoolit C# Application Console
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();
}
}
}
Mag-subscribe sa:
Mga Post (Atom)