How to split a string into two string?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
soytak111
Prole
Posts: 25
Joined: Sat Sep 17, 2022 1:00 am

How to split a string into two string?

Post by soytak111 »

So I have this piece of code like this:

Code: Select all


motif = { "monocolor", "checkerboard"}
selected = "checkerboard"
monocolor = {red,monocolor}
checkerboard = {red,string1,blue,string2}
function love.draw()
    	love.graphics.print(selected,20,20)
end
and i want to split the checkerboard value into "checker" and "board"
how could i split it?
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to split a string into two string?

Post by darkfrei »

soytak111 wrote: Sat Sep 17, 2022 11:16 pm So I have this piece of code like this:

Code: Select all


motif = { "monocolor", "checkerboard"}
selected = "checkerboard"
monocolor = {red,monocolor}
checkerboard = {red,string1,blue,string2}
function love.draw()
    	love.graphics.print(selected,20,20)
end
and i want to split the checkerboard value into "checker" and "board"
how could i split it?

Code: Select all

motives = {
  checkerboard = {name = "checkerboard", color1 = red, color2 = blue, text1 = string1,  text2 = string2},
  monocolor = {name = "monocolor", color1 = red, color2 = red, text1 = string1,  text2 = ""},
}
selected = motives.checkerboard
function love.draw()
 	love.graphics.print(selected.name, 20, 20) 
 end
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to split a string into two string?

Post by pgimeno »

Has anyone else understood what the OP wants?

The best interpretation I can make is that the word is too wide to fit in the place where it needs to be placed, and they want a hyphenation algorithm for automatically splitting words into multiple lines. But I somehow doubt that's the intention.
soytak111
Prole
Posts: 25
Joined: Sat Sep 17, 2022 1:00 am

Re: How to split a string into two string?

Post by soytak111 »

darkfrei wrote: Sun Sep 18, 2022 8:20 am
soytak111 wrote: Sat Sep 17, 2022 11:16 pm So I have this piece of code like this:

Code: Select all


motif = { "monocolor", "checkerboard"}
selected = "checkerboard"
monocolor = {red,monocolor}
checkerboard = {red,string1,blue,string2}
function love.draw()
    	love.graphics.print(selected,20,20)
end
and i want to split the checkerboard value into "checker" and "board"
how could i split it?

Code: Select all

motives = {
  checkerboard = {name = "checkerboard", color1 = red, color2 = blue, text1 = string1,  text2 = string2},
  monocolor = {name = "monocolor", color1 = red, color2 = red, text1 = string1,  text2 = ""},
}
selected = motives.checkerboard
function love.draw()
 	love.graphics.print(selected.name, 20, 20) 
 end
Thank you! This is exactly what I need! :awesome:
lua,contrary to other language,give you as much space as moon :awesome:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 40 guests