Corona extract each character from string - lua

I'm beginner in game development using corona, can you please help me guys how to get every character in a word then add background image to it and make it clickable like in 4 Pics and 1 Word Game. Can you please suggest some ideas or tutorial link. Thanks. So far I don't have enough reputation to put image here but here is the Screenshot Link

Here are some pieces that may help you
1. Iterate over each character
local str="Something"
for i = 1, str:len() do
print(str:sub(i,i));
end
load image
local img = display.newImage("images/" . letter . "1.jpg");
if you need anything specific ask here

To iterate over each character, try also this:
local str="Something"
for c in str:gmatch(".") do
print(c)
end
(Actually, this iterates over each byte in the string, which may not be what you want if the string contains Unicode characters.)

Related

How to use string as equation in Roblox Studio?

So,I have a string, let's say - 1+2-1+9-3 and I need to use it as equation and need to change text to result of this equation. How can i make it? I already did adding numbers to string, so i only need to get result of equation.
If you want to parse the string as a line of code, use loadstring(). This is basically the equivalent to JavaScript's eval(). Just keep in mind you have to allow loadstring to be used on your experience by clicking on ServerScriptService and checking the LoadStringEnabled box under Behaviour.
Example
Code
local parsecode = "1+2-1+9-3"
local parseres = loadstring("return "..parsecode)()
print(parseres)
Code Result
8 - Server - Script:3

New to Coding, how do I combine several print statements into one nicer looking one?

Hi I am new to coding was wondering a simple question, how do I combine this piece of code:
print("Hi, this program is used for the voting system of the new boat name of Ratentango.")
print()
print("The 4 choices for names are:")
print("Boatie Mac Boatface")
print("Bouyonce")
print("Pride of Ratentango")
print("Black Pearl")
print()
print("Please make sure you enter the correct name, as it is case sensitive and any spelling errors will not be counted.")
print()
If not the whole thing, I was thinking just this bit could be combined somehow.
print("The 4 choices for names are:")
print("Boatie Mac Boatface")
print("Bouyonce")
print("Pride of Ratentango")
print("Black Pearl")
Thanks for the help!
I'm assuming you are writing in python, please specify your language to the next questions.
For the answer, you can concentrate the string / variables with , sign between them in the print function call.
Example:
Print ('Hello', 'World','!')
Output : Hello World !
If you want to break line after every sentence you sould add \n in the end of each sentence.
Good luck!

Ruby:-Find the occurrences of a character in a file

I am looking for the Ruby method that can help me find the occurrences of a character in a file.I am looking for all occurrences, not just the first one.
I am able to read the file with the help of File.read("filename").
I do know how to find the no of occurrence in a particular string but dont know how to implement it when finding the characters in the file.
Please help.
Using File.read("filename") is not the most efficient way to do it, but it does not matter unless the file is too big, and if you are using it anyway, then File.read("filename") is indeed a string, so do it as you would with other strings.
File.read("filename").count(some_character)
or
File.new("filename").each_char.inject(0){|n, c| n += 1 if c == some_character; n}

Remove first character from Ruby string using [1..n]

I'm trying to basically trying to remove the . in the the string .extension
So I'm using
'.extension'[1..10] #gives extension
Of course this will work for 10 characters, how would I make it work for any length. I dont know what to search for because I dont know what this array style [x..y] is called.
You can use negative indexes. This will offset them from the end. -1 is the last element, -2 is the second last and so on.
'.extension'[1..-1] # => extension

ERlang - Trying to find LENGTH of constituents of List

guess its getting late, and Im a beginner, just need a little help..
Im trying to find the length of a list.. BUT NOT of the lists themselves, rather the length of the values within..
I take something like:
Other = [<<"366">>,0,
<<1>>,
<<"344">>,<<"Really"
<<1>>,
<<"989">>,<<"NotReally">>
<<1>>,
<<"345">>,4,
<<1>>,
<<"155">>,"209.191"]
I would really want to first convert Other into its RAW constituent binary
Example:
Other = [<<3>>,<<4>>,<<7>>,<<56>>,<<45>>,<<56>>...]
This, of course, is an example of way the original Other would look like(Not right conversion values). So that all of the values in there are there most basic binary data.
Then I could simply iterate through counting each <<_>> and determining the total message length.
Hope I was clear enough to find a solution.
Thanks all for the help, GN
iolist_size/1 is what you are looking for.
1> iolist_size([<<"366">>,0,<<1>>,<<"344">>,<<"Really">>,<<1>>,<<"989">>,<<"NotReally">>,<<1>>,<<"345">>,4,<<1>>,<<"155">>,"209.191"]).
43
2> v(1) - 1.
42
P.S.: Why your example data have this one surplus character? ;-)
If all you're trying to do is find the length of the entire structure, I'd try something like this:
my_length(X) when is_integer(X) -> 1;
my_length(X) when is_binary(X) -> erlang:size(X);
my_length(Lst) when is_list(Lst) ->
lists:sum([my_length(X) || X <- Lst]).
If you really want to build a flat version of your structure, then erlang:list_to_binary gets you pretty close to what you need, then just call size on that. (Actually, this may be better than my first attempt.)
1> erlang:list_to_binary([<<"366">>,0,<<"155">>,"209.191"]).
<<51,54,54,0,49,53,53,50,48,57,46,49,57,49>>

Resources