分析长String

import java.util.ArrayList;

public class PaseString {
	private String code = "A VERY LONG MESS STRING";

	public void pars(String code) {
		char[] chars = code.toCharArray();
		ArrayList<Character> charlist = new ArrayList<Character>();
		boolean canpush = false;
		for (char c : chars) {
			if (c == 'A') {
				canpush = true;
				continue;
			}
			if (c == 'B') {
				printChars(charlist);
				charlist.clear();
				canpush = false;
			}
			if (canpush)
				charlist.add(c);
		}
	}

	private void printChars(ArrayList<Character> list) {
		System.out.print(list);
		System.out.println();
	}

	public static void main(String[] str) {
		PaseString test = new PaseString();
		String longString = "ASD564BSDFAS@#$DF5468BASDF588%^&94BAWEF684/89BA56S42234@#$DF7BSDFS&*()SEFASEF242B";
		test.pars(longString);
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

}

你可能感兴趣的:(java,C++,c,C#)