当前位置:网站首页>Kettle references external scripts to complete phone number cleaning, de duplication and indentation
Kettle references external scripts to complete phone number cleaning, de duplication and indentation
2022-07-27 19:21:00 【The bearer of dark cuisine】
The project needs to judge whether the phone is true , And remove duplicates .
Quote in the project today java When the script performs data cleaning , establish List<String> After that, the program will report various errors .
Ask the great God for advice ~~~
So I refer to Zhang Xiaofan vip Of kettle Case 4 uses java Script for data processing , Solved the problems encountered .
1、 Phone cleaning
There are two kinds of telephones : Landline 、 mobile phone
The cleaning rules are as follows :
Regular match out all the numbers ; Delete the first non 0 All before the number 0; Judge the remaining figures :
Less than 8 Bit phone : Delete ;
8 Bit phone :5,6,8 Keep the beginning , Otherwise, the invalid landline will be deleted ;
9 Bit phone :1 start : If connected 5,6,8, Wrong local landline , After reservation 8 position ; Ruodi 2 It's not 5,6,8, Wrong cell phone number , Delete . Not 1 start : Add in front 0, Abnormal landline number ;
10 Bit phone :1 Position as 1:2 Position as 0 or 1:(3 Position as 5,6,8, Wrong local landline , After reservation 8 position ;3 Bit non 5,6,8, Wrong phone number );2 Bit non 0 or 1: Wrong phone number , Delete .1 Bit non 1, Seat number , Add in front 0;
11 Bit phone :1 Position as 1: if 2:3 Position as 00,10,11,01, And 4 position 5,6,8, Then local landline , After reservation 8 position ; Otherwise, it is the mobile number .1 Bit non 1, Local plane , Add 0;
11 More than 10 phone numbers :1 Position as 1: Wrong cell phone number ;1 Bit non 1, Local plane , Add 0;
The core java The code is as follows :
// Functions needed to remove double indent
package cyt.com.dudu.cyt;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class phoneClean {
// Verify the mobile number function
public static final String CleaningPhone (String sPhone){
String regEx = "[^0-9]";// Match numbers in the specified range
try {
// Take out the blank space and - Arrange the landline
//1、 Determine whether it is null
if(sPhone.indexOf(" empty ")!=-1){
return " empty ";
}else {
// Use regularization to remove magazines except numbers
//Pattern It's a compiled representation of regular expressions
Pattern p = Pattern.compile(regEx);
// One Matcher Object is a state machine , It is based on Pattern Object as a match pattern to expand the string match check .
Matcher m = p.matcher(sPhone);
String string = m.replaceAll(" ").trim();
// Take out the front zero
String sPhone1 = string.replaceAll("\\s*", "");
System.out.println(sPhone1);
for(int b=0; b<sPhone1.length();b++){
System.out.println(b);
if(sPhone1.substring(0, b+1).equals("0")){
sPhone1 = sPhone1.substring(1);
System.out.println(sPhone1);
}else {
System.out.println(" First non 0. Jump out of ");
break ;
}
}
// Judge whether the first two are 86
if(sPhone1.substring(0, 2).equals("86")){
sPhone1 = sPhone1.substring(2);
System.out.println(sPhone1);
}else {
// The first two are not 86, Judge the length of its mobile number
int phonenum = sPhone1.length();
System.out.println(" Length of mobile phone number :" + phonenum );
if(phonenum<8){
sPhone1 = " empty " ;
}else if(phonenum==8){
if(sPhone1.substring(0, 1).equals("5") ||sPhone1.substring(0, 1).equals("6") ||sPhone1.substring(0, 1).equals("8") ){
}else{
sPhone1 = " empty " ;
}
}else if(phonenum==9){
if(sPhone1.substring(0, 1).equals("1") ){
if(sPhone1.substring(1, 2).equals("5") ||sPhone1.substring(1, 2).equals("6") ||sPhone1.substring(1, 2).equals("8")){
sPhone1 = sPhone1.substring(1);
System.out.println("1 At the beginning 9 Cell phone number , Delete 1 Keep the last eight :"+sPhone1);
}else{
sPhone1 = " empty " ;
}
}else{
sPhone1 = " empty " ;
}
}else if(phonenum==10){
if(sPhone1.substring(0, 1).equals("1") ){
if(sPhone1.substring(1, 2).equals("0") ||sPhone1.substring(1, 2).equals("1") ){
if(sPhone1.substring(2, 3).equals("5") ||sPhone1.substring(2, 3).equals("6") ||sPhone1.substring(2, 3).equals("8")){
sPhone1 = sPhone1.substring(2);
System.out.println("1 start ,2 position 0 or 1,3 position 5、6、8 Of 10 Cell phone number , Keep the last eight :"+sPhone1);
}else{
sPhone1 = " empty " ;
}
}else{
sPhone1 = " empty " ;
}
}else{
sPhone1 = "0" + sPhone1 ;
}
}else if(phonenum==11){
if(sPhone1.substring(0, 1).equals("1") ){
if(sPhone1.substring(1, 2).equals("0") ||sPhone1.substring(1, 2).equals("1") ){
if(sPhone1.substring(2, 3).equals("0") ||sPhone1.substring(2, 3).equals("1") ){
if(sPhone1.substring(3, 4).equals("5") ||sPhone1.substring(3, 4).equals("6") ||sPhone1.substring(3, 4).equals("8"))
sPhone1 = sPhone1.substring(3);
System.out.println("1 start ,2、3 position 0 or 1,4 position 5、6、8 Of 11 Seat number , Keep the last eight :"+sPhone1);
}else{
sPhone1 = " empty " ;
}
sPhone1 = sPhone1.substring(1);
System.out.println("1 At the beginning 9 Cell phone number , Delete 1 Keep the last eight :"+sPhone1);
}else{
System.out.println(" Eleven digit mobile number :"+ sPhone1 );
}
}else{
sPhone1 = "0" + sPhone1 ;
}
}else if(phonenum>11){
if(sPhone1.substring(0, 1).equals("1") ){
sPhone1 = " empty " ;
}else{
sPhone1 = "0" + sPhone1 ;
System.out.println(sPhone1);
}
}
}
// The phone number after sorting
System.out.println(" The phone number after sorting :" + sPhone1 );
return sPhone1;
}
} catch (Exception e) {
return " empty ";
}
}
}
2、 Telephone de duplication
I wanted to use an array to remove duplicates , Return to one list Array . How kettle Reported a strange error about the array , So using StringBuffer Complete the stitching
public static final String toReenter(String phone1,String phone2,String phone3,String phone4,String phone5 ){
List<String> phoneListTest = new ArrayList<>();
phoneListTest.add(phone1);
phoneListTest.add(phone2);
phoneListTest.add(phone3);
phoneListTest.add(phone4);
phoneListTest.add(phone5);
StringBuffer phoneList = new StringBuffer();
for(int b=0;b<5;b++){
if(b==0){
phoneList.append(phoneListTest.get(b).toString());
phoneList.append(",");
}else {
if(phoneList.indexOf(phoneListTest.get(b).toString())!=-1){
}else {
phoneList.append(phoneListTest.get(b).toString());
phoneList.append(",");
}
}
}
return phoneList.toString() ;
}3、kettle Realization
kettle You need to judge whether the field is empty , There have been various problems about empty fields before , So this time, we will directly judge the fields with null values , assignment .

The core functions have been uploaded to my blog , You can find it yourself .
边栏推荐
- Unity学习笔记(刚体-物理-碰撞器-触发器)
- C语言打印菱形
- Analysis of Eureka server
- 微机原理学习笔记-常见寻址方式
- C language case: password setting and login > clear solution getchar and scanf
- MongoDB学习笔记(1)——安装MongoDB及其相关配置
- Express get/post/delete... Request
- Micaz+tinyos learning notes (1)
- 进行接口测试时,连接数据库,对数据源进行备份、还原、验证操作
- kettle入门级操作第一篇(读取excel、输出excel)
猜你喜欢

Kinect for Unity3D——BackgroundRemovalDemo学习

web UI 自动化测试:Selenium 语法详解 史上最全

IDEA成功连接Database但不显示表怎么办

进行接口测试时,连接数据库,对数据源进行备份、还原、验证操作

MySQL learning notes (2) -- stored procedures and stored functions

"Testing novice encyclopedia" 5-minute quick start pytest automated testing framework

express

200行代码快速入门文档型数据库MonogoDB

Introduction to assembly language (1)

编程式跳转
随机推荐
Dynamic proxy
Webmagic+selenium+chromedriver+jdbc grabs data vertically.
X-shell remote connection virtual machine
又有一个Repeater的例子
图的遍历的定义以及深度优先搜索和广度优先搜索(二)
Jmeter接口自动化-如何解决请求头Content-Type冲突问题
如何用自动化测试搞垮团队
Power control
MongoDB学习笔记(1)——安装MongoDB及其相关配置
Greedy method, matroid and submodular function (refer)
Nodejs template engine EJS
webservice的疑问
Using vscode to build u-boot development environment
Basic concepts of Nacos and single machine deployment
Normal distribution, lognormal distribution, generation of normal random numbers
200 lines of code quick start document database monogodb
There is another example of repeater
Questions about webservice
Kinect2 for unity3d - avatardemo learning
阿里云对象存储OSS的开通和使用