\\ is \ and \ is used to escape special characters(such as ", ', \), instead you should translate them as following:
local line = "\\\\" --to avoid having to escape special characters, add a property here, for example TextLabel.Text
local result = line:gsub("\\\\", "\\") --\\\\ is \\ and \\ is \
print(result)
Unfortunately this solution would not work for me,
I am attempting to make a LUA Emulator and I want to have the actual magic character incase in the code editor a player types in
local var = "Test \n Test"
which when in the emulator would start out as "Test \\n Test " which I am attempting to turn it into simply "Test \n Test " with the special string formatting.
That’s incorrect, you’re unaware that \ is an escape character, lua translates my \\\\ as \\ and \\ as \, as I said try applying my code snippet to see if it works.
I went through to try and find any errors, it seems like it’s because of the way Roblox does their strings. fixed code:
local line = "Test \\\\\n test"
line = line:gsub("%\\+", "\\")
local num = #line:split("\\")
if line:find("\n") then
line = line:gsub("\\","", 1)
end
print(line)
This is a solution for “\n” but I am looking for a solution specifically without referencing the following character for “\”. Such as in a case that a single gsub would for for say “\’”, “\”", “\n” “\”, ect.
I don’t quite understand what you’re asking, but maybe this is helpful:
a = [[\n\]] -- you can define raw literal strings with [[ ]]
print(a) -- \n\
I think it would also help if you walked through, step-by-step, exactly what the problem is. What you’re seeing, and what you want to see. It seems like you’re asking a question involving TextLabels, but I can’t be sure.