I have problem with spliting string by "

I need to split string by " , but i have problem that when there is \" i dont want to split it, but i needto change it to ", my idea was to replace all \" to some char ad this back to " after spliting, but idk what char to use so it wont be anywhere else


A way that I get around this problem is by using ’ as opposed to ", heres an example since its weird to explain:

print('Johnny asked "Whats for lunch today?", and I responded with lasagna.')

this is solutin, but i use it in command system and i need to use the standart way with " because with " or ’ i have ony 2 levels

What do you mean by


You could use string.sub()


when i need your code and i paste it in my system, it wont work because i have " inside ’ and this inside "

I think a solution to your problem might be to concatenate:

print('"Quotation", but I need an apostrophe'.. "heres my apostrophe '")
1 Like

Lets say you are doing a fly command, you could simply do this
:fly Ken
Now Ken isn’t in the server, but Kensizo is, how would we fly them?

function stringfunc(Str,Name)
  return string.find(Str:lower(), Name:lower())
local name = "Ken" --You could define name however you like, you could turn it into a function or anything you wish.
for i,v in pairs(game.Players:GetChildren()) do
  if stringfunc(string.lower(v.Name), string.lower(name)) then
    --do the command stuff here

Edit; you could also do this for commands, it is very easy to implement to commands, if you need an example let me know.

No i have problem, that when i write ;cmd “print("this is out \"this is in\"")”
it will print:
this is out “this is in”
edit sry i cant write 3 \ but i simply do it as in every other programing language that i will escape the " by adding \

You don’t need to concatenate to make a string like that, you can escape the quotes.

local String = "\"Quotation\", but I need an apostropheheres my apostrophe '"

Or you can use long strings.

local String = [["Quotation", but I need an apostropheheres my apostrophe ']]

Try this;

print('Hello my name is Kensizo \"and I like programming"')

That worked fine for me.
Hope this works for you! If not, let me know, I’ll try my best to assist you. :smiley:

you are just repeating it but i am making cmd system and i am spliting string and i need to split is by " but not by \"

If you want to use “ as a splitter, you can do this:

local index = string.find(str, '\"')

To get the index of the “ , then create two substrings using that index as the end of the first string and the start of the second string

I don’t understand how this prevent splitting by \"

I think a lot of the people here may be interpreting your intention with what you are trying to do differently. Perhaps it is best to show some code of what you have done so far, what you would like to input and what you want it to output as a result of the code.

That will give everyone here a better idea of what exactly you want to do and will allow for them to help you.

Ok pasting code is good idea
but pls dont look at var names, i know its messy, but I always do it with this mess
and the code work without problem
local tempcomand = cmd:split(“"”)
for i,v in pairs(tempcomand)do
if v ~= nil and v:len()>0 then
if i%2 == 1 then
local tempcomand2 = v:split(" “)
for _,v2 in pairs(tempcomand2) do
if v2 ~= nil and v2:len()>0 then
and i need if command cointains \" the string wont be splited in this char(”)
edit: and i really dont know why the code pasted as text when i pasted it in code box

\ is an Escape Character, which means that you can add a quote to a string, if you do not use an escape character the compiler will think you are ending the string.

No i am spliting by " so it will split if there is \ or not
I need to split it only by " and not by \" this is all what i need

You are misinterpreting what I am saying.

To have a “ as a string, you must have an escape character.

If not it will think you are closing the argument.

\” - Means insert a double quote character in the text at this point.

It is not looking for \” it is looking for “, that is just how we tell the compiler we want to look for “ without an error.

We are talking about diferent thinks. If you check the code, you can see i am splitting string (that is from text box sended by remote event) by " and i need to make it will not split string by \"(when i am splitting string, it will find " and splitt it by it and it dont check if there is \ in front of the string).