Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

StringReverse


  • Please log in to reply
3 replies to this topic
Invalid User
  • Members
  • 447 posts
  • Last active: Mar 27 2012 01:04 PM
  • Joined: 14 Feb 2005

;Turns "this" into "siht"

StringReverse(String)

{

	StringLen, L, String

	Loop, %L%

	{

		StringRight, StrRight, String, 1

		StringTrimRight, String, String, 1

		ResultString = %ResultString%%StrRight%

	}

	Return ResultString

}

my lame sig :)

shimanov
  • Guests
  • Last active:
  • Joined: --
loop, parse, String

From the "Loop (parse a string)" page in the manual:

Loop, Parse, InputVar [, Delimiters, OmitChars, FutureUse]

If this parameter [Delimiters] is blank or omitted, each character of InputVar will be treated as a separate substring.


This method utilizes AHk's builtin capabilities to parse and index individual characters within a string. Then build ResultString via prefixes in each iteration, rather than suffixes.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Taking shimanovs idea, it would look like this:
StringReverse(String) 

{ 

   Loop, Parse, %String% 

        ResultString = %A_LoopField%%ResultString% 

   Return ResultString 

}
*not tested*
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Invalid User
  • Members
  • 447 posts
  • Last active: Mar 27 2012 01:04 PM
  • Joined: 14 Feb 2005
Dang your absolutly right. And by the way, whats the 'manual'? :roll:
my lame sig :)