|
#1
|
||||
|
||||
|
Example: Get Reverse of String
Code:
-- A function that will reverse and return a string of characters
function fReverseCharacters(argString)
strDataTypedIn = Dialog.Input("Enter some data", "Type in a line of data", "", MB_ICONINFORMATION)
numDataTypedInLength = String.Length(strDataTypedIn)
strDataReturned = ""
for n = 0, numDataTypedInLength do
strCharacter = String.Mid(strDataTypedIn, numDataTypedInLength-n, 1)
strDataReturned = strDataReturned..strCharacter
end
return strDataReturned
end
-- Testing the function
Dialog.Message("Data Returned, but in reverse order", fReverseCharacters("Hi from Intrigued!"))
|
|
#2
|
||||
|
||||
|
I was going to suggest string.reverse, but I think that's only available in a newer version of lua (5.1?).
So instead I'll suggest two alternative versions using older built-in lua functions for educational purposes: Code:
function GetReversed(str)
local reversed = "";
for i = string.len(str), 1, -1 do
reversed = reversed..string.sub(str,i,i);
end
return reversed;
end
Code:
function GetReversed(str)
local reversed = "";
for i = 1, string.len(str) do
reversed = string.sub(str,i,i)..reversed;
end
return reversed;
end
__________________
--[[ Indigo Rose Software Developer ]] |
|
#3
|
||||
|
||||
|
Thanks Lorne.
|
|
#4
|
||||
|
||||
|
Thank you both.
One of the uses of this function could be with Right to Left languages. Although AMS supports them, it can come handy for the use with other apps that do not. Thanks Yossi |
|
#5
|
||||
|
||||
|
No problem Yosik. I'm glad they will come in handy sooner or later.
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| table to string | ZenLunatic | AutoPlay Media Studio 6.0 | 8 | 09-26-2006 12:49 PM |
| Write from input to string and use resulting string as reffrence for string find in a | Wonderboy | AutoPlay Media Studio 6.0 | 19 | 05-23-2006 12:40 PM |
| Cross-Eyed XML | Worm | Developer's Den | 7 | 09-01-2005 09:55 AM |
| attempt to index a string value | csd214 | AutoPlay Media Studio 5.0 | 8 | 08-08-2004 02:23 AM |
| "Get Delimited String" -- Delimiter can be a string? | Bishal | Setup Factory 6.0 | 1 | 10-16-2003 11:40 AM |
All times are GMT -6. The time now is 08:24 AM.








Linear Mode

