ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/StringUtils.java
Revision: 1.1
Committed: Sun Feb 4 04:56:08 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Log Message:
A new class providing methods (ok, one method) to manipulate String objects.
These methods are really the sort of thing you'd expect Java to have... but it
doesn't :/

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.util;
3    
4     //---IMPORTS---
5     import java.util.*;
6    
7     /**
8     * A class containing useful methods for manipulating
9     * String objects.
10     *
11     * @author $Author$
12     * @version $Id$
13     */
14     public class StringUtils {
15    
16     //---FINAL ATTRIBUTES---
17    
18     /**
19     * The current CVS revision of this class
20     */
21     public static final String REVISION = "$Revision: 1.1 $";
22    
23     //---STATIC METHODS---
24    
25     /**
26     * Searches a string and replaces all occurences
27     * of the given search text with the given replacement
28     * text.
29     *
30     * @param text the text to search and replace in
31     * @param search the string to look for and replace
32     * @param replace the text to replace with
33     * @return the updated version of text
34     */
35     public static String replaceText(String text, String search, String replace) {
36     StringBuffer textBuffer = new StringBuffer(text);
37     int currIndex = 0;
38     currIndex = text.indexOf(search, currIndex);
39     while(currIndex != -1) {
40     if (currIndex != -1) {
41     textBuffer.delete(currIndex, currIndex + search.length());
42     textBuffer.insert(currIndex, replace);
43     }
44     text = textBuffer.toString();
45     currIndex = text.indexOf(search, currIndex + search.length());
46     }
47     return new String(textBuffer);
48     }
49    
50     //---CONSTRUCTORS---
51    
52     //---PUBLIC METHODS---
53    
54     /**
55     * Overrides the {@link java.lang.Object#toString() Object.toString()}
56     * method to provide clean logging (every class should have this).
57     *
58     * This uses the uk.ac.ukc.iscream.util.FormatName class
59     * to format the toString()
60     *
61     * @return the name of this class and its CVS revision
62     */
63     public String toString() {
64     return FormatName.getName(
65     _name,
66     getClass().getName(),
67     REVISION);
68     }
69    
70     //---PRIVATE METHODS---
71    
72     //---ACCESSOR/MUTATOR METHODS---
73    
74     //---ATTRIBUTES---
75    
76     /**
77     * This is the friendly identifier of the
78     * component this class is running in.
79     * eg, a Filter may be called "filter1",
80     * If this class does not have an owning
81     * component, a name from the configuration
82     * can be placed here. This name could also
83     * be changed to null for utility classes.
84     */
85     private String _name = null;
86    
87     //---STATIC ATTRIBUTES---
88    
89     }