We have answer of your question!

100% solved queries, no empty question

Question: replace two same character with whitespace


0

I am trying to replace the string below with whitespaces using javascript

    function replaceString()
    {
        var str = "ABC**EFG";
        return str.replace(/\*/g, " ");
    }

I received the result as ABC EFG but I expect the result to come with two whitespace. I also tried the same thing using php str.replace but still get the same result.

Is there any other methods i can used to replace the individual asterisk with whitespace??

P/S: The return string will be used as part of the sql query


[UPDATE]

I ended up return the string without any replacement to sql, then I use sql replace function to perform replacement in the query.

Question author Noobie | Source

Answer


1


If you're displaying the resulting string in an HTML element then two or more whitespaces will be displayed as only one whitespace. To workaround this fact, use   instead:

return str.replace(/\*/g, ' ');
Answer author Noobie

Tickanswer.com is providing the only single recommended solution of the question replace two same character with whitespace under the categories i.e javascript , . Our team of experts filter the best solution for you.

Related Search Queries:

replace multiple spaces with one sed ,


You may also add your answer

Thanks for contributing an answer to Tick Answer!