Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string and replace dot char in Lua

I have a string stored in sqlite database and I've assigned it to a var, e.g. string

string = "First line and string. This should be another string in a new line"

I want to split this string into two separated strings, the dot (.) must be replace with (\n) new line char

At the moment I'm stuck and any help would be great!!

for row in db:nrows("SELECT * FROM contents WHERE section='accounts'") do
    tabledata[int] = string.gsub(row.contentName, "%.", "\n")
    int = int+1
end

I tried the other questions posted here in stachoverflow but with zero luck

like image 824
Mustafa Avatar asked Oct 25 '25 14:10

Mustafa


1 Answers

What about this solution:`

s = "First line and string. This should be another string in a new line"
a,b=s:match"([^.]*).(.*)"
print(a)
print(b)
like image 125
hendrik Avatar answered Oct 28 '25 02:10

hendrik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!