How to insert a single letter inside a string

how can I insert a single letter in a string?

like “abc” + d = “abcd”

local abc = "abc"
local d = "d"

print(abc.. d)
1 Like

id like to add more like somehow insert it inside a string without using …

Concatenation is the simplest way to add letters into a string, what do you mean by “add more”?

1 Like

like if I have a string of letters such as “123456789”
id like to keep adding more over time

You can use the ..= operator for that I believe

local text = "abc"
text ..= "d"
print(text) --prints abcd

Future additions will be appended to the end of the string, @GoteeSign’s method is the same as how I did it

1 Like
local abc = “abc”
abc = abc..'d'
1 Like

Like the whole alphabet to be added over time?

1 Like

that works but that’s only used once.

id like to be able to keep adding more and more

like if i’m inserting something in a table

If you want to add something else, just use it again

local text = "abc"
text..= "d"

--Later on

text ..= "e"
print(text) --Prints abcde

What are you trying to do?

1 Like
local alphabet = 'abcdefghijklmnopqrstuvwxyz'
local h
local on = 1
while true do
    h = string.sub(alphabet, 1, on)
    on += 1
    print(h)
    if on == 26 then break end
    wait(1)
end

im too lazy to indent

1 Like

string = “”

for i,v in pairs(alphabet)
      insert(v,string)
end

So you want to slowly add in the alphabet to a text? then just do this

local alphabet = 'abcdefghijklmnopqrstuvwxyz'
local text = ""

for i = 1, #alphabet do
	text = alphabet:sub(1, i)
	print(text)
	wait(1)
end
2 Likes

so the alphabet is tons of numbers inside a table
and id like to add more as time goes on

Wait can you do #string instead of using string.len?

1 Like

Your thing is still vague, try saying what you want step by step, the best I understood was the code I did

@GoteeSign And yes, # works for strings as well

2 Likes

I just realized that i can simply just do

String = String..tostring(v)

would that work?

2 Likes

If v is somethign that can be turned into a string, yes. But it’s simpler to do

String ..= tostring(v)
1 Like

Kinda depends on how you are using it in your script

1 Like