Javascript Remove Braces

前端 未结 4 1822
臣服心动
臣服心动 2021-02-05 19:12

I have the string \"{Street Name}, {City}, {Country}\" and want to remove all braces. The result should be \"Street Name, City, County\". How do I do that?

相关标签:
4条回答
  • 2021-02-05 19:35

    Use this javascript simple code in your respective function to remove braces :

            var str = '{Street Name}, {City}, {Country}';
            str = str.replace(/{/g, '').replace(/}/g, '');
    
    0 讨论(0)
  • 2021-02-05 19:38
    str = str.replace(/[{}]/g,"");
    
    0 讨论(0)
  • 2021-02-05 19:41

    The character class [{}] will find all curly braces

    var address = "{Street Name}, {City}, {Country}";
    address = address.replace( /[{}]/g, '' );
    console.log( address ) // Street Name, City, Country
    
    0 讨论(0)
  • 2021-02-05 19:45

    If you want to remove all occurrences of { and } whether or not they are matched pairs, you can do it like this:

    var str = "{Street Name}, {City}, {Country}";
    str = str.replace(/[{}]/g, "");
    
    0 讨论(0)
提交回复
热议问题