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!
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
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 −
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
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP