In: Computer Science
Using C# .NET Core console application that contains the following:
1. Use this variable:
string baconIpsum = "Bacon ipsum dolor amet picanha tri-tip pig pork bacon turducken. Leberkas short ribs prosciutto pork belly ribeye capicola alcatra short loin ham hock rump jowl pig flank beef. Venison tenderloin tail, cupim salami pastrami meatball jerky filet mignon. Salami jerky short loin, chicken pig pork tenderloin rump meatball sausage pancetta sirloin. Drumstick tenderloin ham pork belly cupim, ground round prosciutto jerky ball tip kielbasa tongue andouille picanha alcatra. Ham ribeye t-bone, boudin buffalo pork chop beef tri-tip. Bacon filet mignon frankfurter kevin, pork chop burgdoggen bacon bacon ham hock beef ribs bresaola turkey meatball corned beef.";
2. Use string manipulation, output of a count of how many sentences are in your string variable
3. Use a loop to iterate through each sentence
4. If the string "bacon" is found in the sentence, output a happy sentence, otherwise, output a sad sentence to the console
5. Output how many times bacon is in baconIpsum and tell if that is enough bacon for you
Application Name :baconApplication
Type of Application :Console Application
IDE used :Visual Studio 2019
Program.cs :
//namespace
using System;
//application namespace
namespace baconApplication
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//declaring variable baconIpsum
string baconIpsum = "Bacon ipsum dolor amet picanha tri-tip pig
pork bacon turducken. Leberkas short ribs prosciutto pork belly
ribeye capicola alcatra short loin ham hock rump jowl pig flank
beef. Venison tenderloin tail, cupim salami pastrami meatball jerky
filet mignon. Salami jerky short loin, chicken pig pork tenderloin
rump meatball sausage pancetta sirloin. Drumstick tenderloin ham
pork belly cupim, ground round prosciutto jerky ball tip kielbasa
tongue andouille picanha alcatra. Ham ribeye t-bone, boudin buffalo
pork chop beef tri-tip. Bacon filet mignon frankfurter kevin, pork
chop burgdoggen bacon bacon ham hock beef ribs bresaola turkey
meatball corned beef.";
//converting string baconIpsum to array
string[] sentenceCount = baconIpsum.Split(".");
//print number of sentence
Console.WriteLine("Number of sentences are in string variable
baconIpsum :" + (sentenceCount.Length-1));
//declared variable to store to count word bacon in
baconIpsum
int countBacon = 0;
//using for loop
for (int i = 0; i < sentenceCount.Length-1; i++)
{
//checking if sentence contains string bacon
if (sentenceCount[i].ToLower().Contains ("bacon"))
{
countBacon++;//increment bacon count
//when sentence contains string bacon
//print sentence and string happy sentence
Console.WriteLine(sentenceCount[i]+ ". : happy sentence");
}
else
{
//when sentence does not contains string bacon
//print sentence and string sad sentence
Console.WriteLine(sentenceCount[i] + ". : sad sentence");
}
}
Console.WriteLine("Bacon count : "+countBacon);
}
}
}
===============================================
Output :