Substring Acting Oddly

Hi :wave:

I’m trying to do something really simple. Read a string, and remove the first character.
It’s honestly breaking my heart that I’m even writing this to be honest.

local str = "$1"
local amount = string.sub(str, 2)
print(string.len(amount))
print(amount)

-- Outputs --
2
�1

image

If someone could put me out of my misery that would be fantastic!
Many thanks :smiley:

I don’t know about you, but it worked for me.
image
There are probably better ways to do this, though. For example, I used the string.match method.

local str = "$14621"
local amount = string.sub(str, 2) -- Your example

local split = string.match(str,'%d+') -- Mine; %d is any digit, the + after wards makes sure it scans the whole string, also known as a flag.

print(string.len(amount))
print(amount)
print(split)

Lmk if you have any issues with that.

:bowing_woman:t2:Kon’nichiwa! Yoooo!

--You can use gsub
local String = "$12"
String = string.gsub(String,".","",1)
print(String)

--Output--
--12
1 Like