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



發佈了39 篇原創文章 · 獲贊 16 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章