Finding quotation marks in a string

What do you want to achieve?
I want to find quotation marks in a string.

What is the issue?
You can’t put quotation marks in quotation marks.

What solutions have you tried so far?
Nothing just yet.

Here is basically how I would like it to work.

local exampleString = " "sdknkadnka"  "

print(string.find(exampleString, """) --I want it to print 2, 2.

You can use ' for your string, so '"Something In Quotations"'

local exampleString = ' "sdknkadnka" ' -- You don't need to put spaces after the apostrophe's I just did that for visibility 

print(string.find(exampleString, '"') 

Your script is confused between the quotation marks that start and end the string, and those that are inside the string. There are two ways to solve this:

-- using single quotations
local exampleString = '"string"'
print(string.find(exampleString, '"'))

-- OUTPUT:
-- 1 1
-- using a backslash to avoid closing the string
local exampleString = "\"string\""
print(string.find(exampleString, "\""))

-- OUTPUT:
-- 1 1

I added spaces so the apostrophes were more visible

Thanks for both your replies. It worked. I don’t really know if I can mark both of them as solution so…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.