zj
2026-01-11 28701d9c708089cd64e3dc813ad1d9079de6528a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.nq.utils;
 
/**
 * @program: dabaogp
 * @description:
 * @create: 2025-04-02 18:27
 **/
public class UserNameUtil {
 
    // 去除空格并将非英文字符转换成英文
    public static String formatCustomerName(String customerName) {
        if (customerName == null) {
            return null;  // 如果输入为null,返回null
        }
 
        // 步骤1: 去除所有空格
        String nameWithoutSpaces = customerName.replaceAll("\\s+", "");
 
        // 步骤2: 转换所有非英文字符为英文(例如中文转拼音等)
        String formattedName = convertToEnglish(nameWithoutSpaces);
 
        return formattedName;
    }
 
    // 假设将所有非英文字符转换为其英文拼音或近似字符
    private static String convertToEnglish(String name) {
        // 这里的转换可以根据具体需要进行调整
        // 例如:假设我们只简单地替换一些常见的中文字符为英文
        name = name.replaceAll("[\\p{IsHan}]", "X"); // 将所有汉字替换为 X
 
        // 也可以进一步扩展这里的替换规则
        // 例如,处理某些特殊字符:可以做类似下面的替换
        name = name.replaceAll("[^a-zA-Z]", ""); // 删除所有非字母字符
 
        return name;
    }
 
}