| Paste number 13430: | splitter |
| Pasted by: | dukedave |
| When: | 14 years, 5 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+AD2 |
| Channel: | None |
| Paste contents: |
public ArrayList tokenize(String in) {
//Make arraylist to hold tokens
ArrayList<String> out = new ArrayList<String>();
//We always want first char to trigger new token
boolean lastChar = !isWordChar(in.charAt(0));
//For each character in the string
for(int i=0;i<in.length();i++) {
//If its different prompt a new token
if(isWordChar(in.charAt(i))^lastChar) {
out.add("" + in.charAt(i));
// If its the same add it to the end of the current one
} else {
String temp = out.get(out.size()-1);
out.set(out.size()-1,temp+in.charAt(i));
}
lastChar = isWordChar(in.charAt(i));
}
return out;
}
public boolean isWordChar(char a){
String a2 = new String(""+ a);
return (a2.matches("\\W"));
}Annotations for this paste:
| Annotation number 1: | splitter 2 |
| Pasted by: | dukedave |
| When: | 14 years, 5 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+AD2/1 |
| Paste contents: |
public ArrayList tokenize(String in) {
//Make arraylist to hold tokens
ArrayList<String> out = new ArrayList<String>();
//We always want first char to trigger new token
boolean lastChar = !Character.isLetterOrDigit(in.charAt(0));
//For each character in the string
for(int i=0;i<in.length();i++) {
//If its different prompt a new token
if(Character.isLetterOrDigit(in.charAt(i))^lastChar) {
out.add("" + in.charAt(i));
// If its the same add it to the end of the current one
} else {
String temp = out.get(out.size()-1);
out.set(out.size()-1,temp+in.charAt(i));
}
lastChar = Character.isLetterOrDigit(in.charAt(i));
}
return out;
}