Java tutorial
//package com.java2s; /* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2012 Alejandro P. Revilla * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Converts a string[] into a comma-delimited String. * * Takes care of escaping commas using a backlash * @see com.newland.mtypex.iso.core.jpos.iso.ISOUtil#commaDecode(String) * @param ss string array to be comma encoded * @return comma encoded string */ public static String commaEncode(String[] ss) { StringBuilder sb = new StringBuilder(); for (String s : ss) { if (sb.length() > 0) sb.append(','); if (s != null) { for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch (c) { case '\\': case ',': sb.append('\\'); break; } sb.append(c); } } } return sb.toString(); } }