Jump to content

Search the Community

Showing results for tags 'string replace whole word'.

  • 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. StringReplace is great but sometimes you want to replace a whole instead of partially, for example StringReplace will replace the word 'word' in 'wording', whereas this function won't do that. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringReplaceWholeWord ; Description ...: Replaces substrings in a string, but will replace the whole word instead of if the word is contained within another. ; Syntax ........: _StringReplaceWholeWord($sString, $sSearchString, $sReplaceString[, $fCaseSensitive = Default]) ; Parameters ....: $sString - The string to evaluate. ; $sSearchString - The substring to search for. ; $sReplaceString - The replacement string. ; $fCaseSensitive - [optional] Use case-sensitivity. Default is False. ; Return values .: Returns the new string, the number of replacements performed is stored in @extended. ; Author ........: guinness ; Remarks .......: Additional help and advice from SmOke_N. ; Example .......: Yes ; =============================================================================================================================== Func _StringReplaceWholeWord($sString, $sSearchString, $sReplaceString, $fCaseSensitive = Default) Return StringRegExpReplace($sString, ($fCaseSensitive ? '(?-i)' : '(?i)') & '(?<!-)\b' & $sSearchString & '\b(?!-)', StringReplace($sReplaceString, '\', '\\')) EndFunc ;==>_StringReplaceWholeWordExample use of Function: ConsoleWrite(_StringReplaceWholeWord('This is a simple string with a Word and worded.', 'word', '(non-word)', Default) & @CRLF) ConsoleWrite(_StringReplaceWholeWord('This is a simple string with a Word and worded.', 'Word', '(non-word)', True) & @CRLF) ConsoleWrite(_StringReplaceWholeWord('This is a simple string with a Word and worded.', 'word', '(non-word)', True) & @CRLF)SmOke_N's version:
×
×
  • Create New...