Here you can find the source of formatCardNumber(String cardNumber)
public static String formatCardNumber(String cardNumber)
//package com.java2s; /*/*w w w. j av a2 s .com*/ * eID Middleware Project. * Copyright (C) 2010-2013 FedICT. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version * 3.0 as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, see * http://www.gnu.org/licenses/. */ public class Main { public static String formatCardNumber(String cardNumber) { StringBuilder formatted = new StringBuilder(); if (cardNumber.length() == 10 && cardNumber.startsWith("B")) { // B 0123456 78 formatted.append(cardNumber.substring(0, 1)); formatted.append(' '); formatted.append(cardNumber.substring(1, 8)); formatted.append(' '); formatted.append(cardNumber.substring(8)); } else if (cardNumber.length() == 12) { // 012-3456789-01 formatted.append(cardNumber.substring(0, 3)); formatted.append('-'); formatted.append(cardNumber.substring(3, 10)); formatted.append('-'); formatted.append(cardNumber.substring(10)); } else { formatted.append(cardNumber); } return formatted.toString(); } }