How to replace a word with another word?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
santyagoarias
Posts: 2
Joined: 21 Jan 2023, 02:05

How to replace a word with another word?

Post by santyagoarias » 21 Jan 2023, 02:16

Hi!
I am new to AutoHotkey. I solicit your help.

I would like to replace a word with another word in a text. For example, if the word "apple" exists in a text, I would like that word to be replaced by "pear".

How should I write the programming code?

Regards!

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: How to replace a word with another word?

Post by AHKStudent » 21 Jan 2023, 07:50

Code: Select all

string := "the word is apple test script"
newString := strReplace(string, "apple", "orange")
MsgBox, % newString
ExitApp
https://www.autohotkey.com/docs/v1/lib/StrReplace.htm

User avatar
mikeyww
Posts: 27241
Joined: 09 Sep 2014, 18:38

Re: How to replace a word with another word?

Post by mikeyww » 21 Jan 2023, 08:25

Code: Select all

#Requires AutoHotkey v1.1.33
string := "The word is apple. Test my applets script."
newString1 := StrReplace(string, "apple", "orange")
newString2 := RegExReplace(string, "\bapple\b", "orange")
MsgBox % newString1 "`n" newString2

Post Reply

Return to “Ask for Help (v1)”