Jump to content
Macro Express Forums

Editing strings with percent signs


Recommended Posts

This cropped up before in the context of editing URLs and Joe came up with a solution here:

http://pgmacros.invisionzone.com/index.php?showtopic=3639

 

But so far I've been unable to adapt that for the simple macro I'm trying to write.

 

I want to take a set of strings like these from a text box

%My VariableA%

%My VariableB%

%My VariableC%

etc

 

and end up with

My VariableA

My VariableB

My VariableC

etc,

 

ready to paste back to the text box.

 

Short of firing up my text editor I'm darned if I can get my mind around how to do it :(

 

Of course, the issue wouldn't arise if ME Pro allowed an 'escape' character to ensure the percent symbol was treated as a normal text character. I believe that's how other programs and programming languages like PERL (for Regular Expressions) handle it for 'operator' symbols. If others agree, I'll submit a feature request, although I suspect it won't be east to achieve.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Text Box Display: TextBoxToCopy
Window Activate: textboxtocopy
Mouse Move: 50, 50 Relative to Current Window
Delay: 250 milliseconds
Mouse Left Click
Text Type (Simulate Keystrokes): <CONTROL>a
Text Type (Simulate Keystrokes): <CONTROL>c
Delay: 500 milliseconds
Variable Set String %clip% from the clipboard contents
Delay: 500 milliseconds
Variable Modify String: Replace "%" in %clip% with ""
Text Type (Simulate Keystrokes): %clip%
Text Box Close: textboxtocopy
Text Box Display: TextBoxChanged
Delay: 15 seconds

<TEXT BOX DISPLAY Title="TextBoxToCopy" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang3081\\f0\\fs16 %My VariableA%\r\n\\par %My VariableB%\r\n\\par %My VariableC% \\lang1033\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="1" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x02" Delay="0"/>
<WINDOW ACTIVATE Title="textboxtocopy" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>
<MOUSE MOVE Option="\x02" X="50" Y="50" _PROMPT="0x000A"/>
<DELAY Flags="\x02" Time="250"/>
<MOUSE LEFT CLICK/>
<TEXT TYPE Action="0" Text="<CONTROL>a"/>
<TEXT TYPE Action="0" Text="<CONTROL>c"/>
<DELAY Flags="\x02" Time="500"/>
<VARIABLE SET STRING Option="\x02" Destination="%clip%"/>
<DELAY Flags="\x02" Time="500"/>
<VARIABLE MODIFY STRING Option="\x0F" Destination="%clip%" ToReplace="%" All="TRUE" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="%clip%"/>
<TEXT BOX CLOSE Header="textboxtocopy"/>
<TEXT BOX DISPLAY Title="TextBoxChanged" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang3081\\f0\\fs16 %clip%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="1" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x02" Delay="0"/>
<DELAY Flags="\x01" Time="15"/>

Link to comment
Share on other sites

Thanks Paul. My intention was a bit more complex. The results had to go in the same box and had to work with real variables, in use within the same macro. Your method fails in practice because the variables get substituted. As discussed in that thread I referenced.

 

I should have explained more fully. I like to show my variables in Text Box Displays in the form xyz = %xyz%. But that can get quite tedious if done manually, so my macro works as shown below:

 

MEProMacro-01.jpg

 

The idea I finally came up with was to process each line separately, splitting it into two parts: the first character (always a percent symbol) and the remainder. Neither then suffered substitution.

 

What took most time was trying to find a way of working out how many lines there were, for my Repeat loop. My solution was to count vertical pixels between the first and last line and divide by 12! :rolleyes:

 

Can anyone suggest a less obscure method please?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Thanks Paul. My intention was a bit more complex. The results had to go in the same box and had to work with real variables, in use within the same macro. Your method fails in practice because the variables get substituted. As discussed in that thread I referenced.

 

...

 

Can anyone suggest a less obscure method please?

 

--

Terry, East Grinstead, UK

Hey Terry,

 

I think I may have skipped this thread, as my solution would have been what Paul suggested (about replacing the % with

something else), but now that I've tied this thread together in my mind with the other one, I came back. And now that I'm

home I can actually see the embedded images you've provided. And what you're trying to do is something that I would

like to be able to do as well, but have been too lazy to bother working on it.

 

Until now, apparently.

 

From what I can see, you're putting the Variable name in first, and want the macro to copy the variable, duplicate it, and

strip the % from the first instance but not the second. I would personally suggest a different method. Since I hate typing

% signs around my variables, I would recommend typing out only the variable name without % signs, and then run

the following macro (sans text boxes), which will do exactly what you need it to do.

 

It is a very close representation of the macro Cory built and I modified, but now modified further for this particular case:

 

Text Box Display: Copy text
Delay: .25 seconds
Variable Set String %topwindow% to topmost window title
Variable Set to ASCII Char 10 to %LF%
Variable Set to ASCII Char 13 to %CR%
Variable Set String %Clip% from the clipboard contents
Variable Modify String %Clip%: Append Text (%CR%%LF%)
Variable Set Integer %Position% to the position of "%CR%" in %Clip%
Repeat Until %Position% Equals "0"
 Variable Modify Integer %Position%: Decrement
 Variable Modify String: Copy a substring in %Clip%, starting at 1 and %Position% characters long to %Chunk%
 Variable Modify Integer: %Position% = %Position% + 2
 Variable Modify String %Clip%: Delete a substring starting at 1 and %Position% characters long
 Variable Set Integer %Position% to the position of "%CR%" in %Clip%
 Variable Modify String %Output%: Append Text (%Chunk% = %%Chunk%%%CR%%LF%)
End Repeat
Window Activate: %topwindow%
Delay: .25 seconds
Text Type (Use Clipboard and Paste Text): %Output%

<TEXT BOX DISPLAY Title="Copy text" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Copy text to the clipboard, then click OK.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="FALSE" Mode="\x00" Delay="0"/>
<DELAY Flags="\x01" Time=".25"/>
<VARIABLE SET STRING Option="\x05" Destination="%topwindow%"/>
<VARIABLE SET TO ASCII CHAR Value="10" Destination="%LF%"/>
<VARIABLE SET TO ASCII CHAR Value="13" Destination="%CR%"/>
<VARIABLE SET STRING Option="\x02" Destination="%Clip%"/>
<VARIABLE MODIFY STRING Option="\x06" Destination="%Clip%" Value="%CR%%LF%"/>
<VARIABLE SET INTEGER Option="\x0E" Destination="%Position%" Text_Variable="%Clip%" Text="%CR%" Ignore_Case="FALSE"/>
<REPEAT UNTIL Variable="%Position%" Condition="\x00" Value="0"/>
<VARIABLE MODIFY INTEGER Option="\x08" Destination="%Position%"/>
<VARIABLE MODIFY STRING Option="\x09" Destination="%Chunk%" Variable="%Clip%" Start="1" Count="%Position%"/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%Position%" Value1="%Position%" Value2="2"/>
<VARIABLE MODIFY STRING Option="\x0A" Destination="%Clip%" Start="1" Count="%Position%"/>
<VARIABLE SET INTEGER Option="\x0E" Destination="%Position%" Text_Variable="%Clip%" Text="%CR%" Ignore_Case="FALSE"/>
<VARIABLE MODIFY STRING Option="\x06" Destination="%Output%" Value="%Chunk% = %%Chunk%%%CR%%LF%"/>
<END REPEAT/>
<WINDOW ACTIVATE Title="%topwindow%" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>
<DELAY Flags="\x01" Time=".25"/>
<TEXT TYPE Action="1" Text="%Output%"/>

 

The problem I've been having is that it doesn't seem possible to Trim or Save to Clipboard if the contents of the

%Output% variable contains undefined variables in quotes. Now the trick of switching % with something else is a fine

idea, except that you have to switch it back before saving it to the clipboard, at which point the macro fails.

 

So the solution I found and used above is simply to have the macro do a text type paste, requiring that you use some

activate window commands. But all-in-all, it's fairly functional.

Link to comment
Share on other sites

Thanks Steve, nice work! I'll try that clever idea soon.

 

However, I did have a good reason for entering the variables in their full (percentaged) form: you can do it with the Variable button.

 

- Prompts you with a full list of variables from which to choose those to display

- Avoids typing

- Eliminates spelling mistakes

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

- Prompts you with a full list of variables from which to choose those to display
True, and I use it (occasionally)... but it's mouse-intensive and I hate using the mouse... ever.

 

- Avoids typing
I'd rather type than use the mouse :)

 

- Eliminates spelling mistakes
Also true. However I find I misspell more often when I'm worrying about typing % and [ and ]... I frankly hate the whole brackets concept with regard to variable arrays, but I accept them as a necessary evil. I just mis-type them very often. It's nice that the backspace key is located so close to the bracket keys.
Link to comment
Share on other sites

Sounds like you're using a laptop!

 

BTW, I'm curious what your first steps are when replying to a forum post, without using the mouse. Do you tab several times to get to the Reply button, or what? Hotkey-activated macro? :rolleyes:

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Sounds like you're using a laptop!

 

BTW, I'm curious what your first steps are when replying to a forum post, without using the mouse. Do you tab several times to get to the Reply button, or what? Hotkey-activated macro? :rolleyes:

 

--

Terry, East Grinstead, UK

Nope, not using a laptop. I have semi-bad joints, so a lot of repetitive motion gets to me quickly. The back-and-forth of going to and from the mouse all day long bothers my shoulder and my elbow in a hurry.

 

I've also found that, for the most part, anything that can be done from the keyboard is considerably more efficient. I know people who use the mouse to highlight and r-click for copy and paste. I learned how to use Shift and Ctrl+Shift with Arrow keys for highlight so many years ago I can't recall, and I knew Ctrl+C and Ctrl+V for copy/paste before I knew you could use r-click for those functions.

 

So, if it can be done on the keyboard, I do it on the keyboard. If not, I build a macro that will do it through the keyboard. If even that's too cumbersome, then I still use the mouse.

 

When posting to the forum, I navigate with the mouse. Again, it's the repetitive motion of back and forth that is problematical. If my hand is already on the mouse, then it's not a problem. So for functions that leave my hand on the mouse for a few minutes, or for numerous consecutive functions, it isn't a problem. Clicking through websites, for example, is not usually a problem.

 

It's when my job-function (or anything else, really) calls for: Type a word or two, mouse-move and click, Type a word or two, mouse-move and click, etc... that I get annoyed.

 

When using the Variables button within an MEP function (like what we were discussing in this thread), I will usually tab to that button, and Enter to open it, but then the menus themselves can't be opened by any combination of keystrokes (to my knowledge), requiring me to use the mouse. And since the menus are not very efficiently built in the first-place, I hate that method... though I do use it when I really need to.

Link to comment
Share on other sites

I don't understand what Terry is trying to do. Is running a macro to run in the scripting editor? If so I think one can use an alternate symbol, for instance the pipe "|" and then replace it. Many macro variable commands cause an evaluation of variables but apparently the replace does not. I have a macro now that processes the titles of windows and in some cases one will get percents up there. I simply replace them with pips, do my thing, then put them back.

Link to comment
Share on other sites

I don't understand what Terry is trying to do. Is running a macro to run in the scripting editor? If so I think one can use an alternate symbol, for instance the pipe "|" and then replace it. Many macro variable commands cause an evaluation of variables but apparently the replace does not. I have a macro now that processes the titles of windows and in some cases one will get percents up there. I simply replace them with pips, do my thing, then put them back.

That's what I would have done, too, but it doesn't work.

 

You can replace the % with something else, make the macro do all it needs to, then change the "substitute" character(s) back to %s. This all works.

 

But if you try to trim the variable containing the wayward %s, or if you try to save it to the clipboard, the macro fails. It causes a "Variable Not Set or Incorrect Variable Type" error.

Link to comment
Share on other sites

I don't understand what Terry is trying to do.

 

Did you see post #4 above?

 

And post #11 in

http://pgmacros.invisionzone.com/index.php?showtopic=3940

 

Is [he] running a macro to run in the scripting editor?

 

Yes.

 

If so I think one can use an alternate symbol, for instance the pipe "|" and then replace it. Many macro variable commands cause an evaluation of variables but apparently the replace does not. I have a macro now that processes the titles of windows and in some cases one will get percents up there. I simply replace them with pips, do my thing, then put them back.

 

Doesn't work, as Steve explained.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Yeah I see now. Depending on what commands you are performing you can sometimes get away with substitutions. But if it calls for a variable evaluation it's going to be trouble. However I have managed to get around this in many case. Expanding on Steve's example do the trim before the replace.

 

Awhile back I wrote a pair of macros to update the variable type of old ME3 macros from the CDNT arrays to named variable. The first macro simply copies all the script to the clipboard and replaced the percents. It then hunts for every occurrence of a CDNT and lists it saving it and the modified script to a temporary file. I then I manually edit that file by adding a tab after every CDNT and a new variable name. You see in ME3 I kept a list of all the used vars and their description in the notes. I then run the second macro that takes those new values and replaces all the CDNT instances and finally puts the percents back. Then all I have to do is paste the whole lot back into the scripting editor overwriting my old code. Works slick! But on my first attempt it failed for the problem that is the subject of this thread. But by changing the order of how I did things I was eventually able to make it work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...