// takes in a string and returns a vector of any email address contained.
public static Vector getEmailAddressesFromString(String body)
{
Vector v = new Vector();
char[] bodyC = body.toCharArray();
for (int i=0; i<bodyC.length; i++)
{
if (bodyC[i]=='@')
{
//@ found, - grab text before @ sign - until we hit an unallowed char
int j=i;
String beforeAt="";
String afterAt="";
char thisChar=bodyC[j];
while( acceptable( bodyC[j] ) )
{
//we step back each char til we find one that signifies that its outside the email address
thisChar=bodyC[j];
//System.out.println("thisChar:"+thisChar);
beforeAt=thisChar+beforeAt;
j--;
}
//- grab text after @ sign - until we hit an unallowed char
thisChar='@';
j=i;
while (acceptable(bodyC[j]))
{
//we step forward thru each char til we find one that signifies that its outside the email address
thisChar=bodyC[j];
if (i!=j) // so we dont get the @ again
{
afterAt+=thisChar;
}
j++;
}
v.addElement(beforeAt+afterAt);
//System.out.println("~ "+beforeAt+afterAt);
}
}
return v;
}
private static boolean acceptable(char c)
{
if ( c==' ' || c==',' || c=='!' || c=='#' || c=='$' || c=='%' || c=='^' || c=='&' || c=='*' || c==':')
{
return false;
}
return true;
}