File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44// Feedback / Feature Requests / Issues : http://zzzprojects.uservoice.com/forums/283927
55// All ZZZ Projects products: Entity Framework Extensions / Bulk Operations / Extension Methods /Icon Library
66
7- using System ;
87using System . Linq ;
98
109public static partial class Extensions
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2015 ZZZ Projects. All rights reserved
2+ // Licensed under MIT License (MIT) (https://github.com/zzzprojects/Z.ExtensionMethods)
3+ // Website: http://www.zzzprojects.com/
4+ // Feedback / Feature Requests / Issues : http://zzzprojects.uservoice.com/forums/283927
5+ // All ZZZ Projects products: Entity Framework Extensions / Bulk Operations / Extension Methods /Icon Library
6+
7+ using System . Linq ;
8+ using System . Text . RegularExpressions ;
9+
10+ public static partial class Extensions
11+ {
12+ /// <summary>A string extension method that query if '@this' is palindrome.</summary>
13+ /// <param name="this">The @this to act on.</param>
14+ /// <returns>true if palindrome, false if not.</returns>
15+ public static bool IsPalindrome ( this string @this )
16+ {
17+ // Keep only alphanumeric characters
18+
19+ var rgx = new Regex ( "[^a-zA-Z0-9]" ) ;
20+ @this = rgx . Replace ( @this , "" ) ;
21+ return @this . SequenceEqual ( @this . Reverse ( ) ) ;
22+ }
23+ }
Original file line number Diff line number Diff line change 505505 <Compile Include =" System.Single\_CoreObject\Single.InRange.cs" />
506506 <Compile Include =" System.Single\_CoreObject\Single.NotIn.cs" />
507507 <Compile Include =" System.String\String.Br2Nl.cs" />
508+ <Compile Include =" System.String\String.IsPalindrome.cs" />
508509 <Compile Include =" System.String\String.IsAnagram.cs" />
509510 <Compile Include =" System.String\String.StripHtml.cs" />
510511 <Compile Include =" System.String\String.ConcatWith.cs" />
Original file line number Diff line number Diff line change @@ -15,21 +15,21 @@ public class System_String_IsAnagram
1515 public void IsAnagram ( )
1616 {
1717 // Type
18- string @this = "abba" ;
18+ var @this = "abba" ;
1919
2020 // Examples
21- bool value1 = @this . IsAnagram ( "abba" ) ; // return true;
22- bool value2 = @this . IsAnagram ( "abab" ) ; // return false ;
23- bool value3 = @this . IsAnagram ( "aba" ) ; // return false;
24- bool value4 = @this . IsAnagram ( "" ) ; // return false;
25- bool value5 = @this . IsAnagram ( "aba b" ) ; // return false;
21+ var value1 = @this . IsAnagram ( "abba" ) ; // return true;
22+ var value2 = @this . IsAnagram ( "abab" ) ; // return true ;
23+ var value3 = @this . IsAnagram ( "aba" ) ; // return false;
24+ var value4 = @this . IsAnagram ( "" ) ; // return false;
25+ var value5 = @this . IsAnagram ( "aba b" ) ; // return false;
2626
2727 // Unit Test
2828 Assert . IsTrue ( value1 ) ;
29- Assert . IsFalse ( value2 ) ;
29+ Assert . IsTrue ( value2 ) ;
3030 Assert . IsFalse ( value3 ) ;
3131 Assert . IsFalse ( value4 ) ;
3232 Assert . IsFalse ( value5 ) ;
3333 }
3434 }
35- }
35+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2015 ZZZ Projects. All rights reserved
2+ // Licensed under MIT License (MIT) (https://github.com/zzzprojects/Z.ExtensionMethods)
3+ // Website: http://www.zzzprojects.com/
4+ // Feedback / Feature Requests / Issues : http://zzzprojects.uservoice.com/forums/283927
5+ // All ZZZ Projects products: Entity Framework Extensions / Bulk Operations / Extension Methods /Icon Library
6+
7+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
8+
9+ namespace Z . Core . Test
10+ {
11+ [ TestClass ]
12+ public class System_String_IsPalindrome
13+ {
14+ [ TestMethod ]
15+ public void IsPalindrome ( )
16+ {
17+
18+ // Examples
19+ bool value1 = "abba" . IsPalindrome ( ) ; // return true;
20+ bool value2 = "ab ba" . IsPalindrome ( ) ; // return true;
21+ bool value3 = "ab'ba" . IsPalindrome ( ) ; // return true;
22+ bool value4 = "abca" . IsPalindrome ( ) ; // return false;
23+ bool value5 = "ab b ab" . IsPalindrome ( ) ; // return false;
24+
25+ // Unit Test
26+ Assert . IsTrue ( value1 ) ;
27+ Assert . IsTrue ( value2 ) ;
28+ Assert . IsTrue ( value3 ) ;
29+ Assert . IsFalse ( value4 ) ;
30+ Assert . IsFalse ( value5 ) ;
31+ }
32+ }
33+ }
Original file line number Diff line number Diff line change 6161 </Choose >
6262 <ItemGroup >
6363 <Compile Include =" Properties\AssemblyInfo.cs" />
64- <Compile Include =" String.IsAnagram.cs" />
64+ <Compile Include =" System.String\String.IsPalindrome.cs" />
65+ <Compile Include =" System.String\String.IsAnagram.cs" />
6566 <Compile Include =" System.Array\Array.ClearAll.cs" />
6667 <Compile Include =" System.Array\Array.WithinIndex.cs" />
6768 <Compile Include =" System.Boolean\Boolean.IfFalse.cs" />
You can’t perform that action at this time.
0 commit comments