简体   繁体   English

我如何分裂成两个地方?

[英]How do I get to split in two places?

I would like to get something to work, a splitting in two places. 我想找点工作,分成两个地方。

System.out.println( Integer.parseInt(text.getText().split("--")[1]
                    .substring((text.getText().split("--")[1]).split("x")[0])));

does not work. 不起作用。 If I type --400x55 how do I get it to print "400 , 55". 如果键入--400x55如何打印“ --400x55 ”。

I want it to be changeable, so if the user types some different dimensions, it will use those. 我希望它是可更改的,因此,如果用户键入一些不同的尺寸,它将使用这些尺寸。 So how would I do this? 那我该怎么做呢?

Try: 尝试:

String[] tokens = text.split("x");
System.out.println(tokens[0].split("-")[2] + " , " + tokens[1]); // tokenize by -

or 要么

String[] tokens = text.split("x");
System.out.println(tokens[0].split("--")[1] + " , " + tokens[1]); // tokenize by --

Hope this helps. 希望这可以帮助。

    System.out.println(
        Integer.parseInt(
          Arrays.toString(
               text.getText().replaceAll("--","").split("x")
     )
    )
   )
String text="--400x55";
System.out.println(text.split("--")[1]); // gives you 400x55
System.out.println(text.split("--")[1].split("x")[0]); // gives you 400
System.out.println(text.split("--")[1].split("x")[1]); // gives you 55

use Regular expression to split 使用正则表达式进行拆分

"--400x55".split(/\D/)

it gives you ["","","400","55"] 它会给您[“”,“”,“ 400”,“ 55”]

use the above array according to your need 根据需要使用上面的数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM