[Resolved] Trim spaces from a String

Can anyone let me know how to trim spaces from a string?

For Example:

String = "This is my string "
Is there a function that will do something like this:

newString = rTrim(String) ->Trim spaces from right

print(newString)

----Returns
“This is my string”

Thanks in advance…

[import]uid: 64343 topic_id: 29288 reply_id: 329288[/import]

Dozens of ways to do it, though there isn’t a specific trim function built in to Lua.

[lua]myString = "Hello World "
myString = string.gsub(myString , “%s”, “”)[/lua]

Output would be “Hello World”. The %s is simple a space character. Could probably just do " " instead of %s as well.

As an FYI, when it comes to questions in reference to Lua itself you can actually Google your questions and find the answer pretty quick(at least quicker then waiting on a forum response :)) [import]uid: 147305 topic_id: 29288 reply_id: 117758[/import]

Actually, that won’t work as expected. It will just wipes every space character.
You have to anchor the pattern at the end of the string.

myString = "Hello World "  
myString = string.gsub(myString , "%s$", "")  

or

myString:gsub( "%s$", "")  

That’s the same.
Though, Allen, a library of mine should help here. [import]uid: 142361 topic_id: 29288 reply_id: 118087[/import]