小编Bal*_*ala的帖子

这个replaceAll()有什么问题?

我得到的输出x是打印的值,剩下两个println打印空白行.

1.234.567,89



Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

public class Dummy {

    public static void main(String args[]) {
        String x = "1.234.567,89 EUR";
        String e = " EUR";
        x = x.replaceAll(" EUR","");
        System.out.println(x);
        x = x.replaceAll(".", "");
        System.out.println(x);
        x = x.replaceAll(",",".");
        System.out.println(x);
           //System.out.println(x.replaceAll(" EUR","").replaceAll(".","").replaceAll(",","."));
    }
}
Run Code Online (Sandbox Code Playgroud)

java string replaceall

1
推荐指数
1
解决办法
163
查看次数

如何捕获多个webdriver异常时的OR

我试图捕获这样的多个异常,但我得到错误'); expected'.我该怎么做||

   try {
         //find an element here
    }catch( StaleElementReferenceException e || NoSuchElementException e) {
        //do something            
    }
Run Code Online (Sandbox Code Playgroud)

java selenium selenium-webdriver

1
推荐指数
1
解决办法
259
查看次数

如何从数组中出现的字符串中选择整个单词?

我想检查一个长字符串对齐数组并选择匹配的单词.这句话可能是多字such asThis is以上.这就是我到目前为止所拥有的.

str = "This is a demo text for demo..."
w = ["This is", "to", "is", "for demo"]     
w.select{ |w| str.include?w } #=>["This is", "is", "for demo"] 
Run Code Online (Sandbox Code Playgroud)

但在此我不希望我的结果有"进入","得到"等

str = "This is a demo text for demo together within..."
w = ["This is", "to", "is", "for demo", "in", "get"]    
w.select{ |w| str.include?w } #=> ["This is", "to", "is", "for demo", "in", "get"]
Run Code Online (Sandbox Code Playgroud)

str.include?w正在做它应该做的事情.还有其他选择吗?

ruby

1
推荐指数
1
解决办法
74
查看次数

为什么有些方法可以使用注入而有些方法不适用?

我明白我可以传递一个方法inject.例如,

[1,2,3].inject(:+)     #=> 6
Run Code Online (Sandbox Code Playgroud)

但这一个抛出

["1","2","3"].inject(:to_i) #=> TypeError: no implicit conversion of String into Integer
["1","2","3"].inject(:to_s) #=> ArgumentError: wrong number of arguments (1 for 0)
Run Code Online (Sandbox Code Playgroud)

我没有做任何特别的事情,只是想让我的基础知识正确.

ruby

1
推荐指数
1
解决办法
74
查看次数

在Elixir中使用drop_while?

Elixir的文档说明

drop_while(enumerable, fun)
   Drops items at the beginning of the enumerable while fun returns a truthy value
Run Code Online (Sandbox Code Playgroud)

但是我对下面的输出感到困惑。这是否意味着一旦获得!truthy所有其他一切,就被视为错误?

iex> Enum.drop_while([0,1,2,3,4,5], fn(x) -> rem(x,2) == 0 end)
[1,2,3,4,5]
Run Code Online (Sandbox Code Playgroud)

我期望输出是[1,3,5]因为

 iex> Enum.map([0,1,2,3,4,5], fn(x) -> rem(x,2) == 0 end)
[true,false,true,false,true,false]
Run Code Online (Sandbox Code Playgroud)

我试图了解它的工作原理,而不是试图获得我想要的输出(Enum.filter实现结果)

elixir

1
推荐指数
1
解决办法
100
查看次数

如何将整数除以?

应该是213,3333333...,但是320.0.为什么?

int integ = 320;
System.out.println((double) integ / (double) (3/2));
Run Code Online (Sandbox Code Playgroud)

我的意思是:我正在使用double,为什么我会得到整数?

java

-2
推荐指数
1
解决办法
102
查看次数

标签 统计

java ×3

ruby ×2

elixir ×1

replaceall ×1

selenium ×1

selenium-webdriver ×1

string ×1