");">

TestMarquee split("<.+?>");

这个类主要用来将跑马灯的代码区分开,将需要显示的信息按照要求显示,具体细节下来在研究。其中有个String的spilit方法用正则表达式做参数是个很好的知识点,最值的学习String[] str = marquee.split("<.+?>");


import java.util.ArrayList;



import webbet.cycle.vote.common.VoteConstants;


public class TestMarquee {


/**
* @param args
*/
public static void main(String[] args) {
String marquee = "<marquee loop=\"16\" direction=\"left\" behavior=\"scroll\">"
//+ "レース中止:5R6R 電投中止:7R9R</marquee><marquee loop=\"16\" direction=\"left\" behavior=\"scroll\">1R:欠場2番 ギア変更1番1.23→3.21</marquee>"
+


"レース中止:5R6R 電投中止:7R9R</marquee><marquee loop=\"16\" direction=\"left\" behavior=\"scroll\">8R:欠場7番</marquee>";
System.out.println("marquee : " + marquee);
ArrayList list = new TestMarquee().marqueeSplit(marquee);
for (int i = 0; i < list.size(); i++) {
System.out.println("list : " + list.get(i));
}

String a = "1a1s1d1";
System.out.println(a.split("1").length);
}


public ArrayList marqueeSplit(String marquee) {
// 変更情報リスト
ArrayList al = new ArrayList();
String colon = "";
String colonoff = "";
String recordoff = "";
String jyoho = "";
String recordjyoho = "";
if (marquee != null) {
// split by "<..... >"or"<...../>"
String[] str = marquee.split("<.+?>");
for (int i = 0; i < str.length; i++) {
colonoff = str[i];
// 変更情報が「中止」時の処理
if (str[i] != null && !str[i].equals("")
&& str[i].indexOf("中止") > -1) {
// 中止種類名
String info = "";
// 中止レース番
String[] races = null;
// 各中止情報リスト
String[] cancels = str[i].split(" ");
// 中止情報
String[] stop = null;

for (int k = 0; k < cancels.length; k++) {
stop = cancels[k].split(VoteConstants.DAY_COLON);
info = stop[0];
races = stop[1].split("R");
for (int r = 0; r < races.length; r++) {
if (races[r] != null && !races[r].equals("")) {
// 変更情報リストに追加
al.add(races[r] + "R:" + info);
}
}
}
continue;
}
// split by ":"
String[] colonstr = str[i].split(VoteConstants.DAY_COLON);
if (colonstr.length >= 2) {
colon = colonstr[0] + VoteConstants.DAY_COLON;
colonoff = colonstr[1];
}
// split by " "
String[] spacestr = colonoff.split("\\s");
for (int s = 0; s < spacestr.length; s++) {
recordoff = spacestr[s];
int gindex = spacestr[s]
.indexOf(VoteConstants.TELOPE_TITLE_GIA_CHANGE);
int cindex = spacestr[s]
.indexOf(VoteConstants.TELOPE_TITLE_CANCEL_CAR);
int tindex = spacestr[s]
.indexOf(VoteConstants.TELOPE_TITLE_RACE_TEL_CANCEL);
int rindex = spacestr[s]
.indexOf(VoteConstants.TELOPE_TITLE_RACE_CANCEL);
if (gindex != -1) {
recordjyoho = VoteConstants.TELOPE_TITLE_GIA_CHANGE
+ " ";
recordoff = spacestr[s].substring(gindex + 5);
} else if (cindex != -1) {
recordjyoho = VoteConstants.TELOPE_TITLE_CANCEL_CAR;
recordoff = spacestr[s].substring(cindex + 2);
} else if (tindex != -1) {
recordjyoho = VoteConstants.TELOPE_TITLE_RACE_TEL_CANCEL;
recordoff = spacestr[s].substring(tindex + 4);
} else if (rindex != -1) {
recordjyoho = VoteConstants.TELOPE_TITLE_RACE_CANCEL;
recordoff = spacestr[s].substring(rindex + 5);
}
if (!colon.equals("") || !recordjyoho.equals("")
|| !recordoff.equals("")) {
al.add(colon + recordjyoho + recordoff);
}
}
colon = "";
recordjyoho = "";
}
} else {
al.add("");
}
return al;
}

}


控制台输出:

marquee : <marquee loop="16" direction="left" behavior="scroll">レース中止:5R6R 電投中止:7R9R</marquee><marquee loop="16" direction="left" behavior="scroll">8R:欠場7番</marquee>
list : 5R:レース中止
list : 6R:レース中止
list : 7R:電投中止
list : 9R:電投中止
list : 8R:欠場7番
4



你可能感兴趣的:(TestMarquee split("<.+?>");)