formatStarName static method

String formatStarName(
  1. String name
)

将姓名变为*号

Implementation

static String formatStarName(String name) {
  String newStr;
  if (name.length == 2) {
    newStr = "*" + name.substring(1, 2);
  } else if (name.length == 3) {
    newStr = name.substring(0, 1) + "*" + name.substring(2);
  } else if (name.length == 4) {
    newStr = name.substring(0, 2) + "*" + name.substring(3);
  } else if (name.length > 4) {
    newStr = name.substring(0, 2) + "**" + name.substring(4);
  } else {
    newStr = name;
  }
  return newStr;
}