stepping stone Posted August 20, 2009 Share Posted August 20, 2009 Hi, Does somebody knows how to program this :ex. if I have the word "Wherigo", I want to look what the first letter of the word is, so in this example it's "w". Is there a way to check it? Someone gives a word in player and I want to check the first letter of this word and use this letter to compare to another letter. Thank you all Quote Link to comment
Ranger Fox Posted August 20, 2009 Share Posted August 20, 2009 According to what I found in the Lua Programming Reference, you'd do this: local s = "Wherigo" if Wherigo.NoCaseEquals(string.sub(s,1,1),"w") then Wherigo.MessageBox{Text=[[This is the right answer.]]} end Quote Link to comment
Ranger Fox Posted August 20, 2009 Share Posted August 20, 2009 Perhaps I should have elaborated. The arguments in string.sub are: 1) The string from which you're getting a substring (i.e. getting the letter) 2) Counting from the left, the number of the first character you want to include. The numbering starts at 1. 3) The third argument tells lua the number of the last character, inclusive, to stop. I used 1 because you wanted just the first character. Alternatively, you could use a negative number to start counting from the back of the string. For instance string.sub(s,1,-2) would have returned "Wherig". Quote Link to comment
stepping stone Posted August 20, 2009 Author Share Posted August 20, 2009 Thanks Ranger Fox, that's just what I wanted! Greetings Quote Link to comment
Silly Walker Posted August 23, 2009 Share Posted August 23, 2009 (edited) According to what I found in the Lua Programming Reference, you'd do this: local s = "Wherigo" if Wherigo.NoCaseEquals(string.sub(s,1,1),"w") then Wherigo.MessageBox{Text=[[This is the right answer.]]} end How will be the code if you do this with a variabel? Or isn't this possible? Thanks Edited August 23, 2009 by Silly Walker Quote Link to comment
Ranger Fox Posted August 24, 2009 Share Posted August 24, 2009 How will be the code if you do this with a variabel? Or isn't this possible?In my example, "s" is the variable. Remove the first line (where I set the variable) and change "s" in the second to the name of the variable you're using. Quote Link to comment
Silly Walker Posted August 24, 2009 Share Posted August 24, 2009 How will be the code if you do this with a variabel? Or isn't this possible?In my example, "s" is the variable. Remove the first line (where I set the variable) and change "s" in the second to the name of the variable you're using. Thank you very much! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.