Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for far.kix

(view source code of far.kix as plain text)

  1. ; FAR -- Find And Replace,  Version 1.00
  2. ; Search a string for a substring and replace it with another substring
  3. ; Written by Rob van der Woude
  4. ; http://www.robvanderwoude.com
  5.  
  6. If $s = "" OR $r = "" OR $string = ""
  7. 	? "FAR -- Find And Replace,  Version 1.00"
  8. 	? "Search a string for a substring and replace it with another substring"
  9. 	?
  10. 	? "Usage:  KIX32 FAR.KIX $$S=" + Chr(34) + "string1" + Chr(34) + " $$R=" + Chr(34) + "string2"  + Chr(34) + " $$STRING=" + Chr(34) + "string0" + Chr(34)
  11. 	? "Where:  string0 = the string to be searched"
  12. 	? "        string1 = the substring to search for"
  13. 	? "        string2 = the substring that should replace string1"
  14. 	? "All strings must be enclosed in double quotes."
  15. 	?
  16. 	? "Written by Rob van der Woude"
  17. 	? "http://www.robvanderwoude.com"
  18. 	?
  19. 	? "Press any key . . . "
  20. 	Get $dummy
  21. 	Quit 1
  22. EndIf
  23.  
  24. $oldstr = $string
  25. $los    = Len( $oldstr )
  26. $ls     = Len( $s )
  27.  
  28. Do
  29. 	$pos = InStr( $string, $s )
  30. 	If $pos > 0
  31. 		$newstr = $newstr + SubStr( $string, 1, $pos - 1 ) + $r
  32. 		$string = SubStr( $string, $pos + $ls, $los )
  33. 	Else
  34. 		$newstr = $newstr + $string
  35. 		$string = ""
  36. 	EndIf
  37. Until $string = ""
  38.  
  39. ; Create temporary batch file to return new string value
  40. If RedirectOutput( "%TEMP%.\_FAR_.BAT", 1 ) = 0
  41. 	"SET NEWSTRING=$newstr"
  42. Else
  43. 	? "Error writing to file %TEMP%.\_FAR_.BAT"
  44. 	Quit 2
  45. EndIf
  46. ; Stop redirection
  47. If RedirectOutput( "", 0 ) <> 0
  48. 	Shell "%COMSPEC% /K @ECHO Error stopping redirection"
  49. 	Quit 3
  50. EndIf
  51.  
  52. Quit 0
  53.  

page last modified: 2024-04-16; loaded in 0.0195 seconds