Replacing Part of a String Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Replacing Part of a String

21 Aug 2017, 11:15

My brain is having trouble understanding how to replace part of a string. Really, I want to remove a character from a string, but leave the rest of the string intact. So lets sat I have "COPY:ABCD", how would I remove "A" so it then becomes "COPY:BCD"?

It's confusing me...
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Replacing Part of a String  Topic is solved

21 Aug 2017, 12:01

Code: Select all

OldStr = COPY:ABCD

StringReplace, NewStr, OldStr, a


MsgBox OldStr is %OldStr% `n NewStr is %NewStr%
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Replacing Part of a String

21 Aug 2017, 18:12

No, that isn't right. Here's what I'm trying to do:
I have a commandline switch that has multiple flags. I have a gui that allows you to add those flags to the switch, or take them away. Adding is easy, but taking away is tougher for me to grasp. So, the switch is /COPY:<flag><flag><flag><flag>. Here's an excerpt from the code I'm using:

Code: Select all

Copy := "/COPY:"
Gui, Submit, NoHide
	If ( data = 1 )
	{
		IfNotInString, Copy, D
			Copy .= "D"
	}
Now, I have about 5 other flags that get added the same way. Easy. But say I want to (in the gui) change my mind and not set the "data" flag (shown above), but keep the other 5? Or say I select all 6, but want to change my mind on the third flag? How would I take the string with all 6 (/COPY:ABCDEF), decide I don't want the "D" flag, then make it "/COPY:ABCEF"? "data" in the above code represents the variable for the checkbox. 1 = checked, 0 = unchecked. You can see with it being checked, I just concatenate the string. Now, how would I take that string and remove the "D" flag I just put there, but keep the later coded in flags intact? The rest of the code is the same as the excerpt, just different letters for different flags.
If it is StringReplace (which I'm familiar with), I don't see how it will work.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Replacing Part of a String

21 Aug 2017, 18:18

I need to break these down into separate subroutines. That could help me immensely. Let me do that and step back and take a look.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Replacing Part of a String

21 Aug 2017, 18:31

Rindis is correct. I apologize. My code wasn't right at first--I needed to break it down into multiple subroutines (you'd understand if you saw both incorrect and correct code). Thanks for the help. Sorry for being dense.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Lamron750, mikeyww and 225 guests