Skip to content

Instantly share code, notes, and snippets.

@ivankahl
Created April 28, 2015 19:35
Show Gist options
  • Save ivankahl/bc72c82335738aa05b14 to your computer and use it in GitHub Desktop.
Save ivankahl/bc72c82335738aa05b14 to your computer and use it in GitHub Desktop.
Search and Replace.py
# 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