Добавьте файлы проекта.
This commit is contained in:
43
StringUtils.cs
Normal file
43
StringUtils.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace First_week
|
||||
{
|
||||
internal class StringUtils
|
||||
{
|
||||
public static bool IsPalindrome(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
return false;
|
||||
|
||||
string cleaned = new string(s.Where(c => char.IsLetterOrDigit(c)).ToArray()).ToLower();
|
||||
string reversed = new string(cleaned.Reverse().ToArray());
|
||||
|
||||
return cleaned == reversed;
|
||||
}
|
||||
|
||||
public static string ReverseWords(string sentence)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sentence))
|
||||
return sentence;
|
||||
|
||||
var words = sentence.Split(' ');
|
||||
var reversedWords = words.Select(word => new string(word.Reverse().ToArray()));
|
||||
|
||||
return string.Join(" ", reversedWords);
|
||||
}
|
||||
|
||||
public static string RemovePunctuation(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
return s;
|
||||
|
||||
return new string(s.Where(c => !char.IsPunctuation(c)).ToArray());
|
||||
}
|
||||
|
||||
public static bool IsAlphaNumeric(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
return false;
|
||||
|
||||
return s.All(char.IsLetterOrDigit);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user