This is an old utility class I wrote to simulate perl some useful perl
functions from my cgi days. Perhaps it will help. I just added some docs.
One of these days I'll start using the new regular expression classes.
Hope this helps,
Ron
package rjr;
import java.util.*;
import java.sql.*;
import java.io.*;
/**
* Utility class simulates some Perl functions
* <P>
*
* @author Ron Reinhart
*/
public class Perlish {
/***/
public static boolean DEBUG=false;
//----------------------------------------------------------
// perlish utils
//----------------------------------------------------------
/**
* String string=Perlish.join(List,delim);
* @param list
* @param delimiter
*/
public static String join(List list,String delim) {
if (list.size()==0) return "";
String[] strings=new String[list.size()];
list.toArray(strings);
return join(strings,delim);
}
/**
* String string=Perlish.join(strings,delim);
* @param array strings
* @param delimiter
*/
public static String join(String[] strings,String delim) {
if (strings.length==0) return "";
String newstring=strings[0];
for (int i=1;i<strings.length;i++) {
newstring+=delim+strings[i];
}
return newstring;
}
/**
* String string=Perlish.join(strings,delim);
* @param vector
* @param delim
*/
public static String join(Vector vector,String delim) {
if (vector.size()==0) return "";
String newstring=(String)vector.elementAt(0);
for (int i=1;i<vector.size();i++) {
newstring+=delim+(String)vector.elementAt(i);
}
return newstring;
}
/**
* String[] array=Perlish.split(strings,delim);
* @param s
* @param delim
*/
public static String[] split(String s,String delim) {
StringTokenizer st=new StringTokenizer(s,delim);
int ntokens=st.countTokens();
String[] parts=new String[ntokens];
for (int i=0;i<ntokens;i++)
parts[i]=st.nextToken();
return parts;
}
}
Greg Nudelman
<greg.nudelman To: "jdjlist" <[EMAIL PROTECTED]>
@imx.com> cc:
Subject: [jdjlist] String List Compare
03/26/03 01:31
PM
Please respond
to "jdjlist"
I have a DB field of user-entered 2-letter states, separated by a comma.
states = "CA, OR, TX";
or it could be
states = " CA,OR,TX, HI ";
in other words, spacing is inconsistent, but case seems to be OK.
I need to relaibly and FAST! answer:
is state = "CA" in states
Any ideas?
Greg
----------------------------------------------
P.S. this is what we got so far:
1) run a perl script on DB that will remove the extra spacing
2) add the flanking commas to both:
state = ",CA,";
states = ",CA,OR,TX,HI,";
3) states.indexOf(state) != -1
Greg
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to
[EMAIL PROTECTED]
http://www.sys-con.com/fusetalk
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
http://www.sys-con.com/fusetalk