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;
|
}
|
|
}
|