Clear Screen Using C#

karthikeya Boyini
Updated on 22-Jun-2020 13:39:55

11K+ Views

Use the Console.Clear() method to clear screen and the console buffer. When the Clear method is called, the cursor automatically scrolls to the top-left corner of the window.Here, we have cleared the screen and then set the ForegroundColor and BackgroundColor −ConsoleColor newForeColor = ConsoleColor.Blue; ConsoleColor newBackColor = ConsoleColor.Yellow;The following is the complete code −Example Live Demousing System; using System.Collections.Generic; class Program {    static void Main() {       ConsoleColor foreColor = Console.ForegroundColor;       ConsoleColor backColor = Console.BackgroundColor;       Console.WriteLine("Clearing the screen!");       Console.Clear();       ConsoleColor newForeColor = ConsoleColor.Blue;       ConsoleColor newBackColor = ConsoleColor.Yellow;    } }OutputClearing the screen!

Append to StringBuilder in C#

Samual Sam
Updated on 22-Jun-2020 13:39:34

531 Views

The Append() method add content to a StringBuilder.Set a String −StringBuilder str = new StringBuilder();Now, loop through the number of elements you want and use Append () to append to StringBuilder −for (int j = 0; j < 5; j++) {    str.Append(j).Append(" "); }The following is the complete code −Example Live Demousing System; using System.Text; class Program {    static void Main() {       StringBuilder str = new StringBuilder();       for (int j = 0; j < 5; j++) {          str.Append(j).Append(" ");       }       Console.WriteLine(str);    } }Output0 1 2 3 4

Fetch Data from MySQL Table using mysql_fetch_array in PHP

Prabhas
Updated on 22-Jun-2020 13:39:30

748 Views

The function mysql_fetch_array() will return an array with the numeric index if we use the constant MYSQL_NUM as the second argument to it. To illustrate it we are having the following example −ExampleIn this example, we are fetching all the records from a table named ‘Tutorials_tbl’ with the help of PHP script that uses mysql_fetch_array() function using MYSQL_NUM as the second argument in the following example −

Append to StringBuilder in C# with a New Line at the End

karthikeya Boyini
Updated on 22-Jun-2020 13:39:07

3K+ Views

The AppendLine() method appends the content and add a new line on the end.Firstly, set the StringBuilder −StringBuilder str = new StringBuilder();Use AppendLine() −str.AppendLine("Accessories"); str.AppendLine(); str.AppendLine("Electronics");The following is the complete code −Example Live Demousing System; using System.Text; class Demo {    static void Main() {       StringBuilder str = new StringBuilder();       str.AppendLine("Accessories");       str.AppendLine();       str.AppendLine("Electronics");       Console.Write(str);    } }OutputAccessories Electronics

List All Columns of a MySQL View

Samual Sam
Updated on 22-Jun-2020 13:38:47

299 Views

As we know that views are a type of virtual tables and are the composition of tables too hence we can use the same query to list all the columns of a MySQL view as we can list the columns of a MySQL table. In other words, we can use SHOW FULL COLUMNS statement to get the structure of a MySQL view. Its syntax would be as follows −SyntaxSHOW FULL COLUMNS FROM View_name;Here view_name is the name of the view from which we want to get the list of columns.ExampleSuppose if we want to get a list of columns of ... Read More

Replace a String Using StringBuilder

Samual Sam
Updated on 22-Jun-2020 13:38:40

772 Views

Set a String −StringBuilder str = new StringBuilder("Fitness is important");Use the Replace() method to replace a string −str.Replace("important", "essential");The following is the code to replace a string using StringBuilder −Example Live Demousing System; using System.Text; class Demo {    static void Main() {       // Initial String       StringBuilder str = new StringBuilder("Fitness is important");       Console.WriteLine(str.ToString());       // Replace       str.Replace("important", "essential");       // New String       Console.WriteLine(str.ToString());       Console.ReadLine();    } }OutputFitness is important Fitness is essential

Compare the Content of Two StringBuilders

karthikeya Boyini
Updated on 22-Jun-2020 13:38:04

2K+ Views

Equals method is used in C# to compare the content of two StringBuilders.The following are our two StringBuilders −// first StringBuilder str1 = new StringBuilder(); str1.Append("Tim"); str1.Append("Tom"); str1.Append("Henry"); // second StringBuilder str2 = new StringBuilder(); str2.Append("John"); str2.Append("David"); str2.Append("Beth");Now use the Equals() method to compare both the methods −if (str1.Equals(str2)) {    Console.WriteLine("Contents are equal!"); }The following is the complete code −Example Live Demousing System; using System.Text; class Demo {    static void Main() {       // first       StringBuilder str1 = new StringBuilder();       str1.Append("Tim");       str1.Append("Tom");       str1.Append("Henry"); ... Read More

Iterate StringBuilder in a foreach Loop

Samual Sam
Updated on 22-Jun-2020 13:37:06

2K+ Views

Firstly, set a string array and StringBuilder −// string array string[] myStr = { "One", "Two", "Three", "Four" }; StringBuilder str = new StringBuilder("We will print now...").AppendLine();Now, use foreach loop to iterate −foreach (string item in myStr) {    str.Append(item).AppendLine(); }The following is the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       // string array       string[] myStr = { "One", "Two", "Three", "Four" };       StringBuilder str = new StringBuilder("We will print now...").AppendLine();       // foreach loop to append ... Read More

Clear a StringBuilder in C#

karthikeya Boyini
Updated on 22-Jun-2020 13:36:36

2K+ Views

To clear a StringBuilder, use the Clear() method.Let’s say we have set the following StringBuilder −string[] myStr = { "One", "Two", "Three", "Four" }; StringBuilder str = new StringBuilder("We will print now...").AppendLine();Now, use the Clear() method to clear the StringBuilder −str.Clear();Let us see the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       // string array       string[] myStr = { "One", "Two", "Three", "Four" };       StringBuilder str = new StringBuilder("We will print now...").AppendLine();       // foreach loop to append ... Read More

Access a Character in C# StringBuilder

Samual Sam
Updated on 22-Jun-2020 13:35:57

428 Views

Firstly, set the StringBuilder −StringBuilder str = new StringBuilder(); str.Append("premium");To access the 5th character and display it −Console.WriteLine(str[4]);The following is the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       StringBuilder str = new StringBuilder();       str.Append("premium");       Console.WriteLine("String : "+str);       Console.Write("Accessing 5th character : ");       Console.WriteLine(str[4]);    } }OutputString : premium Accessing 5th character : i

Advertisements