Karthikeya Boyini has Published 2193 Articles

Compare the content of two StringBuilders

karthikeya Boyini

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)) ... Read More

Clear a StringBuilder in C#

karthikeya Boyini

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 ... Read More

C# Program to change a character from a string

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 13:35:34

299 Views

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 ... Read More

How can we update any value in MySQL view as we can update the values in MySQL table?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 13:32:30

475 Views

As we know that with the help of UPDATE statement we can update the values in MySQL table and in the similar way we can update the values in MySQL views. The syntax of UPDATE statement would be the same except at the place of table name we have to ... Read More

C# program to determine if Two Words Are Anagrams of Each Other

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 13:25:04

9K+ Views

For anagram, another string would have the same characters present in the first string, but the order of characters can be different.Here, we are checking the following two strings −string str1 = "heater"; string str2 = "reheat";Convert both the strings into character array −char[] ch1 = str1.ToLower().ToCharArray(); char[] ch2 = ... Read More

C# program to find if an array contains duplicate

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 13:24:00

1K+ Views

Set an array −int[] arr = {    89,    12,    56,    89, };Now, create a new Dictionary −var d = new Dictionary < int, int > ();Using the dictionary method ContainsKey(), find the duplicate elements in the array −foreach(var res in arr) {    if (d.ContainsKey(res))   ... Read More

How to compute Average for the Set of Values using C#?

karthikeya Boyini

karthikeya Boyini

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

284 Views

Firstly, set an array with values −int[] myArr = new int[] {    34,    23,    77,    67 };To get the average, firstly get the sum of array elements.Divide the sum with the length of the array and that will give you the average of the elements −int ... Read More

How to Convert Hex String to Hex Number in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 13:04:03

2K+ Views

Firstly, set the Hex String −string str = "7D";Now, use the Convert.ToSByte() method to convert the Hex string to Hex number −Console.WriteLine(Convert.ToSByte(str, 16));Let us see the complete code −Example Live Demousing System; namespace Demo {    public class Program {       public static void Main(string[] args) {   ... Read More

C# program to check whether a given string is Heterogram or not

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 13:03:33

409 Views

Heterogram for a string means the string isn’t having duplicate letters. For example −Mobile Cry LaptopLoop through each word of the string until the length of the string −for (int i = 0; i < len; i++) {    if (val[str[i] - 'a'] == 0)    val[str[i] - 'a'] = ... Read More

Foreach in C++ and C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 12:57:28

626 Views

Foreach in C++C++ 11 introduced foreach loop to traverse over each element. Here is an example −Example Live Demo#include using namespace std; int main() {    int myArr[] = { 99, 15, 67 };    // foreach loop    for (int ele : myArr)    cout

Advertisements