PDA

View Full Version : i tray to revers a text like "dany maor" to "roam ynad"



lnd
05-29-2006, 07:28 AM
i tray to revers a text like "dany maor" to "roam ynad"

i hev a code bat i dont know how to prosid
-----------------------------------------------
result = Input.GetText("Input1");
size = String.Length(result);

numLoopCount = 1;
repeat
--the code
numLoopCount = numLoopCount + 1;
until numLoopCount == size;
------------------------------------------------
in "the code" i wont to take the "d" and put it on thename[1] and take the "a" and put it on thename[2] and the end put all in inutbox/ how i prosid????

bule
05-29-2006, 11:00 AM
result = Input.GetText("Input1");
reverse="";

for count=String.Length(result), 1, -1 do
reverse=reverse..String.Mid(result, count, 1);
end

Lorne
05-29-2006, 11:53 AM
Lua 5.1 has a string.reverse function built into it, but AutoPlay uses Lua 5.0. Here's some code to add a fast string.reverse function to 5.0, which will automatically switch to the built-in string.reverse function if AutoPlay ever upgrades to Lua 5.1 (which may or may not happen in a future version).


-- string.reverse is built into Lua 5.1, but AutoPlay 6 uses Lua 5.0...
-- this test will revert to the built-in string.reverse function
-- if it becomes available to AutoPlay in the future
if not string.reverse then
-- function string.reverse: returns a reversed version of the string you pass to it
function string.reverse(s)
local reversed = "";
-- Use string.gsub to iterate through the string, calling a temporary function
-- on each character. The temporary function just appends the character to the
-- beginning of our "reversed" string.
string.gsub(s,".",function(c)
reversed = c..reversed;
end);
return reversed;
end
end
I haven't profiled this to determine whether it's faster, but it should be a bit faster due to the internalized temporary function.

I've attached a sample project demonstrating its use.