有问题的replaceAll()

时间:2015-10-08 19:30:49

标签: java regex replaceall

也许我错误地使用了replaceAll,但我无法找到它为什么会这样做。我想简单地从字符串中删除$符号然后输出字符串。

link: function listRingOrdersLink(scope, element, attributes, ctrl) {
    scope.$watch(function() {
        /**
         * bindToController puts this info 
         * on the controller object
         */
        return ctrl.orderMade;
     }, function(newValue, oldValue) {
        ringService.fetchRingOrders()
            .then(function(data) {
                /** put the new data on the controller */
                ctrl.ringorders = data;
            }, function(data) { alert(data); });
     });
}

但是,这仍然会输出带符号的$符号。有谁知道为什么会这样?

1 个答案:

答案 0 :(得分:3)

您需要将replaceAll的返回值分配给变量:

s = s.replaceAll("\\D+", "");

因为String对象是不可变的。

相关问题