Popular Post Walid Posted May 29, 2015 Popular Post Posted May 29, 2015 (edited) Hello Guys it's me again, As the tittle says today i'm going to explain to you LUA Strings try to follow me till the end. Let's get started , String is a sequence of characters it can be initialized with three forms which includes: Characters between single 'quotes' : Example 'This is The First Text' Characters between double "quotes" : Example "This is The Second Text" Characters between double [[square brackets]] : Example [[This is The Third Text]] An other example for the above three forms are shown below. Text = {} Text[1] = 'MTA SA' -- Single quotes Text[2] = "The Greatest Game" -- Double quotes Text[3] = [[You Will Ever Play]] -- Double square brackets for i=1,#Text do outputChatBox(Text[i]) end --[[Result : MTA SA The Greatest Game You Will Ever Play]] Escape sequence characters are used in string to change the normal interpretation of character. for more information check the list below: Escape Sequence Use \a bell \b back space \f form feed \n newline \r carriage return \t horizontal tab \v vertical tab \\ backslash \" double quote \' single quote \[ left square bracket \] right square bracket Some Examples: 1) Newline local Test1 = "Hello \nCommunity" outputChatBox(Test1) --[[ Result : Hello Community]] 2) Single quote local Test2 = "Hello \'Community\'" outputChatBox(Test2) --[[ Result : Hello 'Community']] 3) Left/right square bracket local Test3 = "Hello \[Community\]" outputChatBox(Test3) --[[ Result : Hello [Community] ]] Case Manipulation: string.upper(arg) Make all the lower case characters upper case string.lower(arg) Make uppercase characters lower case. Example: ? local Word = "Mta"; outputChatBox(string.upper(Word)) -- Result : MTA outputChatBox(string.lower(Word)) -- Result : mta Replacing a substring: [divbox=#404040]string.gsub(mainString,findString,replaceString) Returns a string by replacing occurrences of findString with replaceString. Example: ? local Text = "I love playing MTA" local NewText = string.gsub(Text,"MTA","FootBall") outputChatBox(NewText) -- Result : I love playing FootBall Finding string.find(string, pattern , index , plain)Returns the start index and end index of the pattern in the main string. Example: local Text = "Nice to meet you" outputChatBox(string.find(Text,"meet")) -- Result: 9 12 Reversing: string.reverse(argument)Reverses a string. Example: local String = "MTA" outputChatBox(string.reverse(String)) -- Result : ATM Formatting strings: string.format(s, ar1, ar2, ...)Returns a formatted string. -- Date Format local date = 3 local month = 2 local year = 2020 outputChatBox(string.format("Date %02d/%02d/%03d", date, month, year)) -- Result: Date 03/02/2020 Character and byte: string.char(str) | string.byte(str) Returns internal numeric and character respresentations Example: local Char = string.char(65,66,67) outputChatBox(Char) -- Result : ABC local Byte = string.byte("ABCDE") outputChatBox(Byte) -- Result : 65 Last function: string.len(string) Check the length of the passed string. string.rep(string, nunber)) Repeating the same string many times. Example: Local String = "MTA" outputChatBox(string.len(String)) -- Result : 3 outputChatBox(string.rep(String,4)) -- Result : MTAMTAMTAMTA A character class is used to represent a set of characters. examples shown below. . > Represents all characters. %a > Represents all letters. %c > Represents all control characters. %d > Represents all digits. %l > Represents all lowercase letters. %p > Represents all punctuation characters. %s > Represents all space characters. %u > Represents all uppercase letters. %w > Represents all alphanumeric characters. %x > Represents all hexadecimal digits. %z > Represents the character with representation 0. If you have any questions, please feel free to ask. Edited October 13, 2016 by Walid 2 3 Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Mann56 Posted May 30, 2015 Posted May 30, 2015 Thank you dude that's what exactly i wanted "When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag" "Have confidence in yourself, no problem is impossible in life"
Mr.unpredictable. Posted May 30, 2015 Posted May 30, 2015 Great job, also add string.count and string.explode usefull functions contributed by Mta users.
xXMADEXx Posted May 30, 2015 Posted May 30, 2015 Great job, also add string.count and string.explode useful functions contributed by Mta users. These "useful functions" are rather useless now, as for they can both be done with MTAs default split function. The Ultimate Lua Tutorial! | MTA PHP SDK
Walid Posted May 30, 2015 Author Posted May 30, 2015 Thank you dude that's what exactly i wanted Great job, also add string.count and string.explode usefull functions contributed by Mta users. These "useful functions" are rather useless now, as for they can both be done with MTAs default split function You're doing well , sir Walid good job . Thx guys. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
xeon17 Posted May 31, 2015 Posted May 31, 2015 Another good tutorial by you, good job! A unique GangWar gamemode waiting for you!Click here for more information.
Anubhav Posted May 31, 2015 Posted May 31, 2015 I found a mistake in 5. Formatting string -- Date Format local date = 3 local month = 2 loal year = 2020 outputChatBox(string.format("Date %02d/%02d/%03d", date, month, year)) -- Result: Date 03/02/2020 See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
Walid Posted May 31, 2015 Author Posted May 31, 2015 Another good tutorial by you, good job! Good Job :] Thx Guys hope it helps. I found a mistake in 5. Formatting string -- Date Format local date = 3 local month = 2 loal year = 2020 outputChatBox(string.format("Date %02d/%02d/%03d", date, month, year)) -- Result: Date 03/02/2020 'C' fixed, thx . Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Enargy, Posted June 1, 2015 Posted June 1, 2015 Thank you for tutorial, I have learned more about strings - Inactivo.
Walid Posted June 1, 2015 Author Posted June 1, 2015 Good tut,gj & keep the good job up Thank you for tutorial, I have learned more about strings Thanks. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
SkatCh Posted June 1, 2015 Posted June 1, 2015 Good tutorial Failure is simply an opportunity to begin again more intelligently - Henry Ford
Walid Posted June 1, 2015 Author Posted June 1, 2015 Good tutorial thx Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
mouamle Posted June 2, 2015 Posted June 2, 2015 and Another good tutorial keep it up Skype : Mouamle1 Telegram : @Mouamle
Walid Posted June 3, 2015 Author Posted June 3, 2015 and Another good tutorial keep it up thank you Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Walid Posted June 5, 2015 Author Posted June 5, 2015 Good one mate! thx Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Dealman Posted June 15, 2015 Posted June 15, 2015 A good addition to this tutorial would be to teach people how to manipulate strings using regular expressions. For example, this can be used to find a URL. This is very useful in case you need to download XHTML files from a website and read through it in order to find a URL. local string1 = "https://forum.multitheftauto.com/posting.php?mode=reply&f=148&t=88427" local findURL = string.match(string1, "http?://[%w-_%.%?%.%+=&]+") print(findURL) -- Prints "https://forum.multitheftauto.com/posting.php?mode=reply&f=148&t=88427" If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
IMariukas Posted June 19, 2015 Posted June 19, 2015 It's good that you make tutorials so more people could learn Lua faster, good job Walid. "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right! - http://www.lua.org/about.html
Walid Posted June 21, 2015 Author Posted June 21, 2015 It's good that you make tutorials so more people could learn Lua faster, good job Walid. thx Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Apo Posted January 10, 2016 Posted January 10, 2016 Good job. thx only god (الله) اشهد ان لا اله الا الله واشهد ان محمد رسول الله
AMARANT Posted January 15, 2016 Posted January 15, 2016 What a nice and good-looking tutorial, mate! Two thumbs up!
Walid Posted March 22, 2016 Author Posted March 22, 2016 What a nice and good-looking tutorial, mate! Two thumbs up! thx Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Recommended Posts