Jump to content
Macro Express Forums

Reversing a text string?

Recommended Posts

I wouldn't like to spend hours attempting this if one of the experts here has already written it please!


With a variable containing any string like c:\abc\xyz\whateverxxx, I want to end up with xxxrevetahw\zyx\cba\:c


Alternatively, can anyone suggest the easiest approach? Ideally I'd like to avoid arrays (they induce headaches) but if needs must...


P.S: In case anyone's curious, I would then use such a sub-macro as part of a macro to find 'xyz' in the above string, where 'whatever' is the only part already known (and doesn't appear elsewhere).


If I solve the reversal procedure myself (or avoid it by finding another approach to the intended macro) I'll report back at once.


Terry, East Grinstead, UK

Link to comment
Share on other sites

OK, I've avoided the need not only for the reversal but also for finding that section of the path.


I was doing that in order to activate an Explorer folder with the title 'whatever' (I don't show full paths in folder titles). But, with a little care before I run the macro, I can use Alt+Tab to get me to it instead.




But a string reversal routine could be useful sometime - and anyway my curiosity is aroused now. So any thoughts would still be welcomed please.


Terry, East Grinstead, UK

Link to comment
Share on other sites

Variable Set String %Input%: Prompt

Variable Set Integer %Length% to the length of variable %Input%

Repeat Start (Repeat %Length% times)

Variable Modify String: Copy a substring in %Input%, starting at %Index% and 1 characters long to %Char%

Variable Modify String %Output%: Append Text String Variable (%Char%)

End Repeat

Text Box Display: Result

<VARIABLE SET STRING Option="\x01" Destination="%Input%" Prompt="Please input a string of characters" Mask="FALSE" OnTop="FALSE" Left="Center" Top="Center" Monitor="0"/>

<VARIABLE SET INTEGER Option="\x0D" Destination="%Length%" Text_Variable="%Input%"/>

<REPEAT START Start="%Length%" Step="-1" Count="%Length%" Save="TRUE" Variable="%Index%"/>

<VARIABLE MODIFY STRING Option="\x09" Destination="%Char%" Variable="%Input%" Start="%Index%" Count="1" NoEmbeddedVars="FALSE"/>

<VARIABLE MODIFY STRING Option="\x07" Destination="%Output%" Variable="%Char%" NoEmbeddedVars="FALSE"/>


<TEXT BOX DISPLAY Title="Result" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 %Output%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

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.

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.

  • Create New...