Converting " to _

Started by !, Feb 14, 2017, 10:39 AM

Previous topic - Next topic

!

Is there any possibility to convert sign>>" to sign>>_
If yes then how.

Discord: zeus#5155

EK.IceFlake

Write a custom dofile function that reads the file, replaces all _ with " and then compiles and executes it.

!

Quote from: EK.IceFlake on Feb 14, 2017, 10:47 AMWrite a custom dofile function that reads the file, replaces all _ with " and then compiles and executes it.
No i mean if player types /cmd text
suppose text contain this sign "
so is there any possibility to convert it to _ .

Discord: zeus#5155

EK.IceFlake

Quote from: zeus on Feb 14, 2017, 10:50 AM
Quote from: EK.IceFlake on Feb 14, 2017, 10:47 AMWrite a custom dofile function that reads the file, replaces all _ with " and then compiles and executes it.
No i mean if player types /cmd text
suppose text contain this sign "
so is there any possibility to convert it to _ .
I'm not sure if string.replace is a function, but if it is
command.replace("\"", "_");

jWeb

#4
function SearchAndReplace(str, search, replace) {
    local li = 0, ci = str.find(search, li), res = "";
    while (ci != null) {
        if (ci > 0) {
            res += str.slice(li, ci);
            res += replace;
        } else res += replace;
        li = ci + search.len(), ci = str.find(search, li);
    }
    if (str.len() > 0) res += str.slice(li);
    return res;
}

local r = SearchAndReplace("and he said \"what?\" before leaving", "\"", "_");
print(r);