w3resource

C# Sharp: Exercises, Practice, Solution

C# Sharp Regular Expression [9 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

1. Write a C# Sharp program to check whether a given string is a valid Hex code or not. Return true if the said string is a valid code otherwise false. Go to the editor
Sample Data:
("#CD5C5C") -> True
("#f08080") -> True
("#E9967A") -> True
("#EFFA07A") -> False
Click me to see the solution

2. Write a C# Sharp program to calculate the average word length in a given string. Round the average length up to two decimal places. Go to the editor
Sample Data:
("CPP Exercises." -> 6
("C# syntax is highly expressive, yet it is also simple and easy to learn.") -> 4
(“C# is an elegant and type-safe object-oriented language") -> 5.62
Click me to see the solution

3. Write a C# Sharp program to check whether a given string of characters can be transformed into a palindrome. Return true otherwise false. Go to the editor
Sample Data:
("amamd") -> True
("pamamd") -> False
("ferre") -> True
Click me to see the solution

4. Write a C# Sharp program to validate a password of length 7 to 16 characters with the following guidelines: Go to the editor
• Length between 7 and 16 characters.
• At least one lowercase letter (a-z).
• At least one uppercase letter (A-Z).
• At least one digit (0-9).
• Supported special characters: ! @ # $ % ^ & * ( ) + = _ - { } [ ] : ; " ' ? < > , .
Sample Data:
("[email protected]") -> True
("W#[email protected]") -> False
("[email protected]") -> False
("sdsd723#$Amid") -> True
("sdsd723#$Amidkiouy") -> False
Click me to see the solution

5. Write a C# Sharp program to check whether two given strings contain the same character pattern. Go to the editor
Sample Data:
("AACC", "PPRR") -> True
("FFGG", "ADAD") -> False
Click me to see the solution

6. Write a C# Sharp program to check for repeated occurrences of words in a given string string. Go to the editor
Sample Data:
("C# C# syntax is highly expressive, yet it is is also simple and easy to to learn learn.") -> 3 matches found
("Red Green Green Black Black Green.") -> 2 matches found
Click me to see the solution

7. Write a C# Sharp program to check whether a given string either represents a currency value or has the correct format to represent a currency value. Go to the editor
Click me to see the solution

8. Write a C# Sharp program to remove the special characters from a given text. Return the new string which allowed alphanumeric characters, spaces, underscores _ and dashes - . Go to the editor
Sample Data:
("[email protected]%^&CC") -> "AACC"
("Python") -> "Python"
("w3resource.com") -> "w3resourcecom"
Click me to see the solution

9. Write a C# Sharp program to find the word "C#" in a given string. If the word "C#" found return "C# document found." otherwise return “Sorry no C# document!". Go to the editor
Sample Data:
("C# Exercises") -> "C# document found."
("Python Exercises") -> "Sorry no C# document!"
("Tutorial on c#") -> "C# document found."
Click me to see the solution

C# Sharp Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Share this Tutorial / Exercise on : Facebook and Twitter