Code: Select all
PORT1 = 2
PORT2 = 2
HIDMOUSE_API = 0
Snap mouse = 1
Code: Select all
PORT1 = 2
PORT2 = 2
HIDMOUSE_API = 0
Snap mouse = 1
Code: Select all
text =
(
PORT1 = 2
PORT2 = 2
HIDMOUSE_API = 0
Snap mouse = 1
)
newPORT1 := 3
newPORT2 := 4
Loop 2 {
text := RegExReplace(text, "m`a)^PORT" . A_Index . "\s*=\s*\K.*$", newPORT%A_Index%)
}
MsgBox, % text
That worked perfectly!teadrinker wrote: ↑21 Jan 2019, 10:30Hi,
try:Code: Select all
text = ( PORT1 = 2 PORT2 = 2 HIDMOUSE_API = 0 Snap mouse = 1 ) newPORT1 := 3 newPORT2 := 4 Loop 2 { text := RegExReplace(text, "m`a)^PORT" . A_Index . "\s*=\s*\K.*$", newPORT%A_Index%) } MsgBox, % text
Code: Select all
text =
(
PORT1 = 2
PORT2 = 2
HIDMOUSE_API = 0
Snap mouse = 1
)
newPORT1 := 3
newPORT2 := 4
Loop, parse, text, `n
{
text := StrReplace(text, "PORT1 = 2", "PORT1 ="A_Space . newPort1)
text := StrReplace(text, "PORT2 = 2", "PORT2 ="A_Space . newPort2)
break
}
MsgBox, % text
That answer would be below... But just playing around with alternatives...teadrinker wrote: ↑24 Jan 2019, 14:21I think that the source text does not necessarily have an exact match "PORT1 = 2", could be "PORT1 = [any number]".
Code: Select all
text =
(
PORT1 = 2
PORT2 = 2
HIDMOUSE_API = 0
Snap mouse = 1
)
newPORT1 := 3
newPORT2 := 4
Loop, parse, text, `n
{
if (A_Index = 1)
{
Output .= "PORT1 =" A_Space . newPort1 "`n"
Output .= "PORT2 =" A_Space . newPort2 "`n"
}
if (A_Index > 2)
Output .= A_Loopfield "`n"
}
text :=""
text := Output
MsgBox, % text
Code: Select all
PORT1 = 2
PORT2 = 2
Not exactly sure on that one. But the programmer is likely to know something about the data in which he is interfacing with. Thus know the rows that need to be replaced or some particular attribute that he can pick on.teadrinker wrote: ↑24 Jan 2019, 15:47What ifare not first and second strings?Code: Select all
PORT1 = 2 PORT2 = 2
Users browsing this forum: doodles333, exodus_cl, ratyrat, Sniperman and 371 guests