Practice 50 C# String Programming Questions, TechnoVlogs

Practice 50 C# String Programming Questions


Q1. Write a C# program to reverse a string.  
  Input: String = "Hello"  
  Output: olleH

Q2. Write a C# program to count the number of vowels in a string.  
  Input: String = "Hello World"  
  Output: Vowels = 3

Q3. Write a C# program to find the length of a string.  
  Input: String = "Programming"  
  Output: Length = 11

Q4. Write a C# program to check if a string is a palindrome.  
  Input: String = "madam"  
  Output: Palindrome

Q5. Write a C# program to concatenate two strings.  
  Input: String1 = "Hello", String2 = "World"  
  Output: HelloWorld

Q6. Write a C# program to convert a string to uppercase.  
  Input: String = "hello"  
  Output: HELLO

Q7. Write a C# program to convert a string to lowercase.  
  Input: String = "HELLO"  
  Output: hello

Q8. Write a C# program to check if a string contains a specific character.  
  Input: String = "Hello", Character = 'e'  
  Output: Character found

Q9. Write a C# program to check if a string starts with a given substring.  
  Input: String = "Hello World", Substring = "Hello"  
  Output: Starts with Hello

Q10. Write a C# program to check if a string ends with a given substring.  
   Input: String = "Hello World", Substring = "World"  
   Output: Ends with World

Q11. Write a C# program to find the index of the first occurrence of a character in a string.  
   Input: String = "Hello", Character = 'l'  
   Output: Index = 2

Q12. Write a C# program to remove all spaces from a string.  
   Input: String = "Hello World"  
   Output: HelloWorld

Q13. Write a C# program to replace all occurrences of a character in a string.  
   Input: String = "Hello World", OldChar = 'o', NewChar = 'x'  
   Output: Hellx Wxrld

Q14. Write a C# program to split a string into an array of substrings.  
   Input: String = "apple,banana,orange", Separator = ','  
   Output: ["apple", "banana", "orange"]

Q15. Write a C# program to check if a string is empty.  
   Input: String = ""  
   Output: String is empty

Q16. Write a C# program to check if a string is null or empty.  
   Input: String = null  
   Output: String is null or empty

Q17. Write a C# program to compare two strings.  
   Input: String1 = "apple", String2 = "apple"  
   Output: Strings are equal

Q18. Write a C# program to find the first occurrence of a substring in a string.  
   Input: String = "Hello World", Substring = "World"  
   Output: Substring found at index 6

Q19. Write a C# program to convert the first letter of each word in a string to uppercase.  
   Input: String = "hello world"  
   Output: Hello World

Q20. Write a C# program to find the last occurrence of a character in a string.  
   Input: String = "Hello World", Character = 'o'  
   Output: Last occurrence at index 7

Q21. Write a C# program to check if a string contains only digits.  
   Input: String = "123456"  
   Output: Contains only digits

Q22. Write a C# program to check if a string contains only alphabetic characters.  
   Input: String = "Hello"  
   Output: Contains only alphabetic characters

Q23. Write a C# program to extract a substring from a string.  
   Input: String = "Hello World", StartIndex = 6, Length = 5  
   Output: World

Q24. Write a C# program to remove a specific character from a string.  
   Input: String = "Hello World", Character = 'o'  
   Output: Hell Wrld

Q25. Write a C# program to check if two strings are anagrams.  
   Input: String1 = "listen", String2 = "silent"  
   Output: Strings are anagrams

Q26. Write a C# program to trim leading and trailing whitespaces from a string.  
   Input: String = "  Hello World  "  
   Output: Hello World

Q27. Write a C# program to convert a string to a character array.  
   Input: String = "Hello"  
   Output: ['H', 'e', 'l', 'l', 'o']

Q28. Write a C# program to check if a string is a valid email address.  
   Input: String = "example@mail.com"  
   Output: Valid email address

Q29. Write a C# program to find the number of words in a string.  
   Input: String = "Hello World"   
   Output: Word count = 2

Q30. Write a C# program to reverse the words in a string.  
   Input: String = "Hello World"  
   Output: World Hello

Q31. Write a C# program to find the ASCII value of a character.  
   Input: Character = 'A'  
   Output: ASCII value = 65

Q32. Write a C# program to count the occurrence of a word in a string.  
   Input: String = "apple banana apple", Word = "apple"  
   Output: Occurrences = 2

Q33. Write a C# program to remove all occurrences of a word in a string.  
   Input: String = "apple banana apple", Word = "apple"  
   Output: banana

Q34. Write a C# program to join an array of strings into a single string.  
   Input: Array = ["apple", "banana", "cherry"]  
   Output: apple banana cherry

Q35. Write a C# program to replace a word in a string with another word.  
   Input: String = "Hello World", OldWord = "World", NewWord = "C#"   
   Output: Hello C#

Q36. Write a C# program to remove all vowels from a string.  
   Input: String = "Hello World"  
   Output: Hll Wrld

Q37. Write a C# program to check if a string is a valid URL.  
   Input: String = "http://example.com"  
   Output: Valid URL

Q38. Write a C# program to check if a string contains a given substring.  
   Input: String = "Hello World", Substring = "World"  
   Output: Contains substring

Q39. Write a C# program to convert a string to a number.  
   Input: String = "123"  
   Output: Number = 123

Q40. Write a C# program to format a string using placeholders.  
   Input: Name = "John", Age = 30  
   Output: Hello John, you are 30 years old

Q41. Write a C# program to remove duplicate characters from a string.  
   Input: String = "aabcc"   
   Output: abc

Q42. Write a C# program to find the longest word in a string.  
   Input: String = "The quick brown fox jumps over the lazy dog"  
   Output: Longest word = jumps

Q43. Write a C# program to convert a string to Title Case.  
   Input: String = "the quick brown fox"  
   Output: The Quick Brown Fox

Q44. Write a C# program to split a string into an array of words.  
   Input: String = "Hello World"  
   Output: ["Hello", "World"]

Q45. Write a C# program to replace a substring in a string using Regex.  
   Input: String = "The cat in the hat", OldWord = "cat", NewWord = "dog"  
   Output: The dog in the hat

Q46. Write a C# program to find the index of a substring in a string.  
   Input: String = "Hello World", Substring = "World"  
   Output: Index = 6

Q47. Write a C# program to check if a string contains digits.  
   Input: String = "abc123"  
   Output: Contains digits

Q48. Write a C# program to remove all punctuation marks from a string.  
   Input: String = "Hello, World!"  
   Output: Hello World

Q49. Write a C# program to convert a string to a boolean value.  
   Input: String = "true"  
   Output: Boolean = True

Q50. Write a C# program to generate a random string of a given length.  
   Input: Length = 5  
   Output: Random String = "abc12"

Share on Social Media