Trending
Nigeria: Gombe PDP Politicising Diphtheria Outbreak - APC is trending now Zamfara Records 367 Confirmed Diphtheria Cases, 320 Recover is trending now Africa accounts for 75% of global Mpox cases in July- WHO is trending now Quantum entanglement confirmed in Z bosons at Large Hadron Collider is trending now Rust prevention coating uses nanotech to self-repair and conquer corrosion is trending now 'If I wanted to go to space, I would have stayed at NASA': What's next for Artemis II ast… is trending now After the refereeing case in the Manchester derby, Rooney snaps: "Enough with VAR, it's h… is trending now Spurs' Richarlison posts 'Why?' and a tearful emoji after he is left out of Liverpool Car… is trending now 'Truly incredible!' - Alvaro Morata backs Lamine Yamal for Ballon d'Or glory after witnes… is trending now London misses out to Nairobi in World Athletics bid is trending now BBNaija S11: Abi, Araga Evicted In Week Seven is trending now Peller quickly retraces his steps after comparing Ochacho’s son’s streams to Champz’s num… is trending now Nigeria: Gombe PDP Politicising Diphtheria Outbreak - APC is trending now Zamfara Records 367 Confirmed Diphtheria Cases, 320 Recover is trending now Africa accounts for 75% of global Mpox cases in July- WHO is trending now Quantum entanglement confirmed in Z bosons at Large Hadron Collider is trending now Rust prevention coating uses nanotech to self-repair and conquer corrosion is trending now 'If I wanted to go to space, I would have stayed at NASA': What's next for Artemis II ast… is trending now After the refereeing case in the Manchester derby, Rooney snaps: "Enough with VAR, it's h… is trending now Spurs' Richarlison posts 'Why?' and a tearful emoji after he is left out of Liverpool Car… is trending now 'Truly incredible!' - Alvaro Morata backs Lamine Yamal for Ballon d'Or glory after witnes… is trending now London misses out to Nairobi in World Athletics bid is trending now BBNaija S11: Abi, Araga Evicted In Week Seven is trending now Peller quickly retraces his steps after comparing Ochacho’s son’s streams to Champz’s num… is trending now
XML

Interview questions on string functions in c#

Interview questions on string functions in c#

 What are the differences between String and StringBuilder in C#?String is immutable, meaning its value cannot be changed after creation. Operations like concatenation create new strings.StringBuilder is mutable and designed for efficient string manipulation. It allows modifications without creating new instances.How do you check if two strings are equal in C#?Use the Equals() method or == operator to compare strings for equality. For instance:string str1 = "Hello"; string str2 = "Hello"; bool areEqual = str1.Equals(str2); // or bool areEqual = (str1 == str2); Explain the difference between String.Substring() and String.Remove() methods.Substring() extracts a substring starting from a specified index and optional length.Remove() removes a specified number of characters starting from a specified index.How can you reverse a string in C#?There are various approaches. One way is to convert the string to an array of characters, then reverse the array and convert it back to a string.string original = "Hello"; char[] charArray = original.ToCharArray(); Array.Reverse(charArray); string reversed = new string(charArray); What is the purpose of String.Split() method?String.Split() divides a string into substrings based on a specified separator and returns an array of strings.string sentence = "Hello, how are you?"; string[] words = sentence.Split(' '); // Splits by space How do you concatenate strings efficiently in C#?Use StringBuilder for concatenating multiple strings. It's more efficient than repeatedly concatenating with + operator or String.Concat() due to its mutability.StringBuilder sb = new StringBuilder(); sb.Append("Hello"); sb.Append(" "); sb.Append("World"); string result = sb.ToString(); Explain the usage of String.Format() method.String.Format() is used to format strings by inserting values into placeholders within a format string.int value = 42; string formatted = string.Format("The answer is {0}", value); // Outputs: "The answer is 42" How would you determine the length of a string in C#?To get the length of a string in C#, I'd use the Length property.For example: string myString = 'Hello';int length = myString.Length;Can you explain the concept of string interpolation in C#?String interpolation in C# allows embedding expressions directly within string literals, making it more readable. I'd use $ before the string and insert variables or expressions within curly braces. For instance: int num = 10;string result = $"The number is {num}";

View original source →

Related