当前位置:网站首页>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 .
边栏推荐
- C language case: password setting and login > clear solution getchar and scanf
- I'm afraid I won't use the JMeter interface testing tool if I accept this practical case
- Big enemies, how to correctly choose the intended enterprises in the new testing industry?
- kettle引用外部脚本完成电话号码清洗、去重缩进
- Sword finger offer17- print from 1 to the maximum n digits - Analog
- Unity learning notes (rigid body physics collider trigger)
- Kinect2 for unity3d - avatardemo learning
- Technology Summit 58 Liu Yuan in the same city was invited to attend qecon 2022 global software quality & effectiveness conference
- web UI 自动化测试:Selenium 语法详解 史上最全
- Unity学习笔记(刚体-物理-碰撞器-触发器)
猜你喜欢

Selenium automated test interview questions family bucket

v-if,v-else,v-for

Kinect for Unity3d----KinectManager

NPM's ID card and dependence

What if idea successfully connects to the database without displaying the table

Express get/post/delete... Request

go-zero单体服务使用泛型简化注册Handler路由

kettle 分列、合并记录

转行软测&跳槽到新公司,工作怎样快速上手?

Unity display Kinect depth data
随机推荐
The go zero singleton service uses generics to simplify the registration of handler routes
Role authorization --- complete the addition and deletion of secondary menus by adding and deleting primary menus
kettle入门级操作第一篇(读取excel、输出excel)
[Luogu p3175] bitwise OR (min max inclusive) (high-dimensional prefix and / FWT)
Usage of ref keyword
Self control principle learning notes - system stability analysis (1) - BIBO stability and Routh criterion
又有一个Repeater的例子
Kinect for Unity3d----KinectManager
An experience
图的遍历的定义以及深度优先搜索和广度优先搜索(二)
WSN journal indexed by SCI
Big enemies, how to correctly choose the intended enterprises in the new testing industry?
Nacos基本概念和单机部署
如何用自动化测试搞垮团队
Opening and using Alibaba cloud object storage OSS
C language case: password setting and login > clear solution getchar and scanf
ipfs通过接口获得公钥、私钥,并加密存储。第一弹
Down sampling - signal phase and aliasing
内存管理A4
Kinect for Unity3d----KinectManager