//------------------------------------------------------------------------------ // Compilation Unit Header //------------------------------------------------------------------------------ // // Name: WayString.java // Author: William A. Shaffer // Package: com.waysysweb.util // Description: // // A collection of string routines. // // // Copyright (c) 2006 Waysys, Inc. All Rights Reserved. // // Permission to use, copy, modify, and distribute this software // and its documentation for NON-COMMERCIAL purposes and without // fee is hereby granted provided that this copyright notice // appears in all copies. // // Waysys MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF // THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Waysys SHALL NOT BE LIABLE FOR // ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR // DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. // // For further information, contact Waysys Inc. at wshaffer@waysysweb.com // or 800-622-5315 (USA). // //------------------------------------------------------------------------------ // Package Declaration //------------------------------------------------------------------------------ package com.waysysweb.util; //------------------------------------------------------------------------------ // Import Declarations //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // Public Class Declaration //------------------------------------------------------------------------------ /** * Utility to do certain string manipulations. * * @author William A. Shaffer * @version 1.01 17-Jun-2000 */ public class WayString extends Object { /** * The string being manipulated */ private String aString; /** * Create an instance of this class * */ public WayString () { aString = ""; } /** * Create an instance of this class with a value. * * @param value the value the string should take on */ public WayString(String value) { aString = value; } /** * Set the string value of the instance. * * @param value the value the instance should take on */ public void setString(String value) { aString = value; } /** * Substitute the argument * * @param sym the character showing where the argument should be inserted * @param arg the argument to be substituted in the string * @return the value of the string with the argument substituted */ public String substitute(char sym, String arg) { String message; int index = aString.indexOf(sym); if (index < 0) { message = aString; } else { message = substring(0, index) + arg + substring(index + 1, aString.length()); } return message; } /** * Return a substring of the string. * * @param beginIndex the beginning index (0 <= beginIndex < length of string) * @param endIndex the ending index (0 <= endIndex < length of string) * @return a substring of the string */ public String substring(int beginIndex, int endIndex) { int lnth = aString.length(); StringBuffer message = new StringBuffer(lnth); int i; for(i = beginIndex; i < endIndex; i++) { if ((i >= 0) && (i < lnth)) { message.append(aString.charAt(i)); } } return message.toString(); } }