Created
April 28, 2015 19:35
-
-
Save ivankahl/bc72c82335738aa05b14 to your computer and use it in GitHub Desktop.
Search and Replace.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script simply searches for all instances of a search term and replaces tgem with supplied text | |
# Ivan Kahl, 28 April 2015 | |
import console | |
import editor | |
def main(): | |
# Get the search term | |
searchFor = console.input_alert('Search Term', 'Enter the term to search for in the text file', '', 'Continue') | |
if not searchFor: | |
return | |
replaceWith = console.input_alert('Replace with Term', 'Enter the term to replace the searched text with', '', 'Continue') | |
if not replaceWith: | |
return | |
text = editor.get_text() | |
text = text.replace(searchFor, replaceWith) | |
editor.replace_text(0, len(text), text) | |
console.hud_alert('Text replaced successfully') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment