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
Let's say our string is −StringBuilder str = new StringBuilder(); str.Append("pre");To change a character, set the value at that particular index. The following sets a character at the 3rd position −str[2] = 'o';Here is the complete code −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { StringBuilder str = new StringBuilder(); str.Append("pre"); Console.WriteLine("String : "+str); Console.WriteLine("Change 3rd character"); str[2] = 'o'; Console.WriteLine("New String : "+str); } }OutputString : pre Change 3rd character New String : pro
Set StringBuilder −StringBuilder str = new StringBuilder("Airport");Let’s say you need to remove characters. For that, use the Remove() method, which removes a bunch of characters beginning with a particular index −str.Remove(3, 4);The above removes four characters beginning from 3rd index (i.e. 4th position) −Here is the complete code −Example Live Demousing System; using System.Text; public class Program { public static void Main() { StringBuilder str = new StringBuilder("Airport"); Console.WriteLine("String: "+str); // removing four characters Console.Write("String after removing characters: "); str.Remove(3, 4); Console.WriteLine(str); } }OutputString: Airport String after removing characters: Air
As we know that PHP provides us the function named mysql_query to create a new database.ExampleTo illustrate this we are creating a database named ‘Tutorials’ with the help of PHP script in the following example − Creating MySQL Database
System programs provide an environment where programs can be developed and executed. In the simplest sense, system programs also provide a bridge between the user interface and system calls. In reality, they are much more complex. For example, a compiler is a complex system program.System Programs PurposeThe system program serves as a part of the operating system. It traditionally lies between the user interface and the system calls. The user view of the system is actually defined by system programs and not system calls because that is what they interact with and system programs are closer to the user interface.An ... Read More
As we know that PHP provides us the function named mysql_select_db to select a mysql database.ExampleTo illustrate this we are selecting a database named ‘Tutorials’ with the help of PHP script in the following example − Selecting MySQL Database
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP