C Sharp Strings Questions and Answers

Practice Mode
Showing 10 of 32 questions
Q21
Which method replaces all occurrences of a specified character in a string?
  • A Replace()
  • B Change()
  • C Substitute()
  • D Swap()
Answer: Option A
Explanation: Replace() method substitutes all instances of old character with new character.
Q22
What does String.IsNullOrEmpty() check for?
  • A Null or empty string
  • B Null or whitespace
  • C Empty or whitespace
  • D Null or zero length
Answer: Option A
Explanation: Checks if string is null or has zero length (empty string).
Q23
Which method converts a string to lowercase?
  • A ToLower()
  • B ToLowerCase()
  • C Lower()
  • D ConvertToLower()
Answer: Option A
Explanation: ToLower() method converts all characters in a string to lowercase.
Q24
What is the purpose of String.Format() method?
  • A Format strings
  • B Compare strings
  • C Concatenate strings
  • D Search strings
Answer: Option A
Explanation: String.Format formats strings by replacing format items with specified values.
Q25
Which method checks if a string starts with a specified substring?
  • A StartsWith()
  • B BeginsWith()
  • C StartWith()
  • D HasPrefix()
Answer: Option A
Explanation: StartsWith() returns true if string begins with the specified value.
Q26
What does "Hello".IndexOf("l") return?
  • A 2
  • B 1
  • C 3
  • D 0
Answer: Option A
Explanation: IndexOf returns the zero-based index of first occurrence of specified character.
Q27
Which method creates a new string by repeating a character multiple times?
  • A new String("c", 5)
  • B String.Repeat("c", 5)
  • C String.Fill("c", 5)
  • D String.Create("c", 5)
Answer: Option A
Explanation: String constructor can create string by repeating character specified times.
Q28
What is string interpolation in C#?
  • A Embed expressions in strings
  • B Compare strings
  • C Convert strings
  • D Encrypt strings
Answer: Option A
Explanation: String interpolation uses $ prefix to embed expressions directly in string literals.
Q29
Which method removes a specified number of characters from a string?
  • A Remove()
  • B Delete()
  • C Cut()
  • D Erase()
Answer: Option A
Explanation: Remove() deletes characters from specified position to end or for given count.
Q30
What is the difference between String and StringBuilder?
  • A String is immutable
  • B String is faster
  • C StringBuilder is immutable
  • D No difference
Answer: Option A
Explanation: String is immutable while StringBuilder is mutable and more efficient for multiple modifications.
Questions and Answers for Competitive Exams Various Entrance Test