Here you can find the source of translate(String s, String identifier, String associator)
Parameter | Description |
---|---|
s | a parameter |
identifier | a parameter |
associator | a parameter |
public static String translate(String s, String identifier, String associator)
//package com.java2s; /**//from w ww . j a v a 2 s .c o m * Function that attempts to fix capitalization of proper names. * <p/> * Example usage: * <pre>{@code * VistaStringUtils.nameCase("RON BURGUNDY"); // => "Ron Burgundy" * VistaStringUtils.nameCase("MCDONALDS"); // => "McDonalds" * }</pre> * <p/> * This is a port of the <pre>NameCase</pre> library, which is a Ruby implementation of Perl's * <pre>Lingua::EN::NameCase</pre> and owes most of its functionality to the Perl version by Mark Summerfield. * <p/> * Original Version: * Copyright (c) Mark Summerfield 1998-2002. <summer@perlpress.com> All Rights Reserved. * <p/> * Ruby Version: * Copyright (c) Aaron Patterson 2006 * <p/> * <pre>NameCase</pre> is distributed under the GPL license. * <p/> * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * <p/> * 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 General Public License for more details. * <p/> * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @param s the String to properly namecase. * @return Returns a new String properly namecased. * @see "http://namecase.rubyforge.org/" * @see "http://www.gnu.org/licenses/" */ public class Main { /** * Performs a character-for-character replacement within a string. * * @param s * @param identifier * @param associator * @return */ public static String translate(String s, String identifier, String associator) { String newString = ""; for (int index = 0; index < s.length(); index++) { String substring = s.substring(index, index + 1); int position = identifier.indexOf(substring); if (position != -1) newString = newString + associator.substring(position, position + 1); else newString = newString + s.substring(index, index + 1); } return newString; } }