我有这个代码,它采用格式为255.255.255.255的IP地址(字符串),并需要对这些数字(此处未发布)执行一些后处理,但必须将字符串转换为整数数组.
我在这里使用了split()方法,但它没有给我结果.我在sp上做了正则表达式的其他答案,但没有一个对我有效.
import java.util.Scanner;
public class Main{
public static void main(String args[]){
String text;
Scanner take=new Scanner(System.in);
text=take.nextLine();
String data[]=text.split(".",4);
for(String w:data){
System.out.println(w);
}
take.close();
}
}
Run Code Online (Sandbox Code Playgroud)
我已尝试输入12.36.26.25
但它输出36.26.25,应该是12 36 26 25
我正在尝试解决很多用户使用包含“~”的语法的情况。如下:
select
business_postal_code as zip,
count(distinct case when left(business_address,1) ~ '^[0-9]' then lower(split_part(business_address, ' ', 2))
else lower(split_part(business_address, ' ', 1)) end ) as n_street
from sf_restaurant_health_violations
where business_postal_code is not null
group by 1
order by 2 desc, 1 asc;
Run Code Online (Sandbox Code Playgroud)
访问案例的链接:https://platform.stratascratch.com/coding/10182-number-of-streets-per-zip-code ?python=
但我无法理解这部分代码实际上是如何工作的:... ~ '^ ....