String Capitalized

Super simple function to include. Really not sure why its missing from the Corona SDK…
[lua]function string.capital( str )
local firstLetter = string.sub(string.upper(str), 1, 1);
local otherLetters = string.sub(str, 2);

return firstLetter…otherLetters;
end[/lua] [import]uid: 50514 topic_id: 19135 reply_id: 319135[/import]

Maybe because Ansca isn’t making the standart LUA Functions.
But this can be also done this way

function firstToUpper(str)  
 return (str:gsub("^%l", string.upper))  
end  

It’s kind of easy to make it, I don’t think this should be implemented. [import]uid: 13097 topic_id: 19135 reply_id: 73779[/import]

Im only saying it should, because theres a lot of noobs out there. The less code someone needs to figure out how to write, the happier they are. I think for the community it should be implemented. [import]uid: 50514 topic_id: 19135 reply_id: 74655[/import]

Use string:upper. It’s built-in to Corona SDK.

I found about it here: http://lua-users.org/wiki/StringLibraryTutorial

Example:

print(string.upper("small world")) [import]uid: 7026 topic_id: 19135 reply_id: 75875[/import]

[lua]string.upper()[/lua] is not the right function for Capitalization.

A ‘capital’ string would look like this : Hello
An ‘upper’ string would look like this : HELLO [import]uid: 50514 topic_id: 19135 reply_id: 75944[/import]

I have included in Tools Library, apart from many other features, a few useful string manipulation functions with support for most common special characters:

[lua]string.split(“Lorem-Ipsum”, “-”) --> Lorem Ipsum

string.upper(“àáâäå”) --> ÀÁÂÄÅ

string.lower(“ÀÁÂÄÅ”) --> àáâäå

string.title(“LOREM iPsUm”) --> Loren Ipsum

string.charAt(“Lorem Ipsum”, 3) --> r[/lua]

Check it out here:
http://toolslib.blogspot.com/ [import]uid: 10048 topic_id: 19135 reply_id: 78291[/import]