Paste number 13430: splitter

Index of paste annotations: 1

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:
Raw Source | XML | Display As
	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:
Raw Source | Display As
	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;
		
	}

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.