Last change
on this file since 10737 was 10737, checked in by kjdon, 19 years ago |
Java Wrapper for GDBM, from Martin Pool. Original website gone, so added it all in here. I have modified the Makefiles to work in greenstone, and on macs, and added windows makefiles
|
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.2 KB
|
Line | |
---|
1 | /*
|
---|
2 | * Copyright (C) 1997 by Pharos IP Pty Ltd
|
---|
3 | * Confidential. All rights reserved.
|
---|
4 | * $Id: StringOps.java 10737 2005-10-19 03:06:40Z kjdon $
|
---|
5 | * $Source$
|
---|
6 | *
|
---|
7 | * ``No strings attached.''
|
---|
8 | */
|
---|
9 |
|
---|
10 | package au.com.pharos.util;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Mixed bag of string manipulation functions. It would be nice if
|
---|
14 | * some of these were in <CODE>java.lang.String</CODE>, but since
|
---|
15 | * they're not, they're implemented as static functions within this
|
---|
16 | * class.
|
---|
17 | *
|
---|
18 | * Typical use:
|
---|
19 | * <PRE>
|
---|
20 | * String foo = "some string"
|
---|
21 | * int cnt = StringOps.countOccurrences(foo, 's');
|
---|
22 | * // --> cnt == 2
|
---|
23 | * </PRE>
|
---|
24 | *
|
---|
25 | * @author Martin Pool
|
---|
26 | * @version $Revision: 10737 $, $Date: 2005-10-19 03:06:40 +0000 (Wed, 19 Oct 2005) $
|
---|
27 | **/
|
---|
28 | public class StringOps
|
---|
29 | {
|
---|
30 | /** This class contains only static public functions. **/
|
---|
31 | private StringOps() { ; }
|
---|
32 |
|
---|
33 | /** Count the number of occurences of a character in a
|
---|
34 | * string.
|
---|
35 | *
|
---|
36 | * @param needle the character to search
|
---|
37 | * @param haystack string to be searched
|
---|
38 | *
|
---|
39 | * @return 0 if <EM>needle</EM> does not occur in <EM>haystack</EM>;
|
---|
40 | * or a positive number indicating the number of occurrences
|
---|
41 | **/
|
---|
42 | static public int countOccurrences(String haystack, char needle)
|
---|
43 | {
|
---|
44 | byte[] hay = haystack.getBytes();
|
---|
45 | int count = 0;
|
---|
46 | for (int i = 0; i < hay.length; i++)
|
---|
47 | if (hay[i] == needle)
|
---|
48 | count++;
|
---|
49 | return count;
|
---|
50 | }
|
---|
51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.