Indigo Rose Software
  #1  
Old 12-13-2006
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,059
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!"))
__________________
Intrigued
www.amsuser.com
Reply With Quote
  #2  
Old 12-14-2006
Lorne's Avatar
Lorne Lorne is offline
Indigo Rose Staff Member
 
Join Date: Feb 2001
Location: Indigo Rose Software
Posts: 2,588
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
(The first version is possibly more efficient, but I couldn't say for sure without timing it.)
__________________
--[[ Indigo Rose Software Developer ]]
Reply With Quote
  #3  
Old 12-14-2006
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,059
Thanks Lorne.
__________________
Intrigued
www.amsuser.com
Reply With Quote
  #4  
Old 12-15-2006
yosik's Avatar
yosik yosik is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Israel
Posts: 1,863
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
Reply With Quote
  #5  
Old 12-15-2006
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,059
No problem Yosik. I'm glad they will come in handy sooner or later.

__________________
Intrigued
www.amsuser.com
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software