Jump to content

Search the Community

Showing results for tags 'palindrome string check'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. This is a quick little function to check whether or not a string is a Palindrome. Function: Optimised version. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsPalindrome ; Description ...: Check if a string is a palindrome. ; Syntax ........: _IsPalindrome($sString) ; Parameters ....: $sString - A string value containing the palindrome. ; $bRetainNonAlphaNumeric - [optional] Retain all non-word characters. Default is False. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Remarks .......: Characters are checked with the case ignored i.e. A == a and Z == z. ; Example .......: Yes ; =============================================================================================================================== Func _IsPalindrome($sString, $bRetainNonAlphaNumeric = Default) If Not $bRetainNonAlphaNumeric Then $sString = StringRegExpReplace($sString, '\W', '') EndIf Return $sString = StringReverse($sString) EndFunc ;==>_IsPalindromeFunction: With custom StringReverse() ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsPalindrome ; Description ...: Check if a string is a palindrome. ; Syntax ........: _IsPalindrome($sString) ; Parameters ....: $sString - A string value containing the palindrome. ; $bRetainNonAlphaNumeric - [optional] Retain all non-word characters. Default is False. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Remarks .......: Characters are checked with the case ignored i.e. A == a and Z == z. ; Example .......: Yes ; =============================================================================================================================== Func _IsPalindrome($sString, $bRetainNonAlphaNumeric = Default) If Not $bRetainNonAlphaNumeric Then $sString = StringRegExpReplace($sString, '\W', '') EndIf Local Const $iChar_Length = 1 Local $bReturn = True, _ $i = 1, $j = StringLen($sString) While ($i < $j) ; Converted from this: http://marc.info/?l=php-general&m=120422082915762 If Not (StringMid($sString, $i, $iChar_Length) = StringMid($sString, $j, $iChar_Length)) Then $bReturn = False ExitLoop EndIf $i += 1 $j -= 1 WEnd Return $bReturn EndFunc ;==>_IsPalindromeExample use of Function: Example() Func Example() ConsoleWrite('Racecar: ' & _IsPalindrome('Racecar') & @CRLF) ConsoleWrite('String: ' & _IsPalindrome('String') & @CRLF) ConsoleWrite('A man, a plan, a canal, Panama: ' & _IsPalindrome('A man, a plan, a canal, Panama!') & @CRLF) ConsoleWrite('Palindrome: ' & _IsPalindrome('Palindrome') & @CRLF) ConsoleWrite('Was it a car or a cat I saw?: ' & _IsPalindrome('Was it a car or a cat I saw?', True) & @CRLF) ; This is a palindrome, but the flag has been set to True, so will return False, due to symbols being retained. ConsoleWrite('Elk rap song? No sparkle: ' & _IsPalindrome('Elk rap song? No sparkle') & @CRLF) ConsoleWrite('I saw desserts; I''d no lemons, alas no melon! Distressed was I: ' & _IsPalindrome('I saw desserts; I''d no lemons, alas no melon! Distressed was I') & @CRLF) EndFunc ;==>Example
×
×
  • Create New...