- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
Have you ever repeated the same string manipulation logic across multiple files? I did—until I learned the power of string extensions.
While building the Employee Performance Review System, I created some helpful string extension methods to make my code cleaner and more reusable.
? 1. ??????? ?? ????? ????
? ?????????????: Capitalizes the first letter of each word in a string (e.g., full names).
var name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input.ToLower());
// "john doe" → "John Doe"
? 2. ????? ???? ????
? ?????????????: Removes all HTML tags from a string to display plain text.
var plainText = Regex.Replace(input, "<.*?>", string.Empty);
// "
Hello
" → "Hello"
? ?. ????? ?? ?????? ?? ???????
? ?????????????: Validates whether a string contains only digits.
bool isNumeric = input.All(char.IsDigit);
// "12345" → true, "12a45" → false
??? ? ??? ?????? ??????????:
• Improves ???? ???????????
• Promotes ??? (???'? ?????? ????????) principles
• Makes unit testing easier
These methods are now part of my helper library and reused across multiple layers — from view models to services.
? ???? ?????? ??????? ?? ??? ??? ????? ?? ???? ?????????
While building the Employee Performance Review System, I created some helpful string extension methods to make my code cleaner and more reusable.
? 1. ??????? ?? ????? ????
? ?????????????: Capitalizes the first letter of each word in a string (e.g., full names).
var name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input.ToLower());
// "john doe" → "John Doe"
? 2. ????? ???? ????
? ?????????????: Removes all HTML tags from a string to display plain text.
var plainText = Regex.Replace(input, "<.*?>", string.Empty);
// "
Hello
" → "Hello"
? ?. ????? ?? ?????? ?? ???????
? ?????????????: Validates whether a string contains only digits.
bool isNumeric = input.All(char.IsDigit);
// "12345" → true, "12a45" → false
??? ? ??? ?????? ??????????:
• Improves ???? ???????????
• Promotes ??? (???'? ?????? ????????) principles
• Makes unit testing easier
These methods are now part of my helper library and reused across multiple layers — from view models to services.
? ???? ?????? ??????? ?? ??? ??? ????? ?? ???? ?????????