Vice City: Multiplayer

VC:MP Discussion => General Discussion => Topic started by: ! on Feb 14, 2017, 10:39 AM

Title: Converting " to _
Post by: ! on Feb 14, 2017, 10:39 AM
Is there any possibility to convert sign>>" to sign>>_
If yes then how.
Title: Re: Converting " to _
Post by: EK.IceFlake on Feb 14, 2017, 10:47 AM
Write a custom dofile function that reads the file, replaces all _ with " and then compiles and executes it.
Title: Re: Converting " to _
Post by: ! 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 _ .
Title: Re: Converting " to _
Post by: EK.IceFlake on Feb 14, 2017, 11:39 AM
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("\"", "_");
Title: Re: Converting " to _
Post by: jWeb on Feb 14, 2017, 12:34 PM
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);