private void writeToLabelWords(DataStruct data) { String dataLine_view = data.getEnglishWord(); dataLine_view += " "; if (data.getChineseWord1() != "") { dataLine_view += data.getChineseWord1(); dataLine_view += "; "; } if (data.getChineseWord2() != "") { dataLine_view += data.getChineseWord2(); dataLine_view += "; "; } if (data.getChineseWord3() != "") { dataLine_view += data.getChineseWord3(); dataLine_view += "; "; } if (data.getChineseWord4() != "") { dataLine_view += data.getChineseWord4(); dataLine_view += "; "; } dataLine_view += "\n"; labelWords.Text += dataLine_view; }
private List<DataStruct> getwords(String source) { List<DataStruct> tmp_dataList = new List<DataStruct>(); string restult = ""; String[] tmp_data_word_info = null; String[] tmp_data_word = source.Split('{'); for (int i = 1; i < tmp_data_word.Length; i++) { DataStruct tmp_data = new DataStruct(); tmp_data_word_info = tmp_data_word[i].Split('['); for (int j = 1; j < tmp_data_word_info.Length; j++) { if (tmp_data_word_info[j].StartsWith("Unit:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("Unit:", ""); restult = restult.Replace("]", ""); if (restult != "") { try { tmp_data.setUnit(Int32.Parse(restult)); } catch { MessageBox.Show("Unit is not a number"); break; } } } else if (tmp_data_word_info[j].StartsWith("EnglishWord:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("EnglishWord:", ""); restult = restult.Replace("]", ""); tmp_data.setEnglishWord(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord1:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord1:", ""); restult = restult.Replace("]", ""); tmp_data.setChineseWord1(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord2:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord2:", ""); restult = restult.Replace("]", ""); tmp_data.setChineseWord2(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord3:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord3:", ""); restult = restult.Replace("]", ""); tmp_data.setChineseWord3(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord4:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord4:", ""); restult = restult.Replace("]", ""); tmp_data.setChineseWord4(restult); } else if (tmp_data_word_info[j].StartsWith("Tested:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("Tested:", ""); restult = restult.Replace("]", ""); tmp_data.setTested(bool.Parse(restult)); } else if (tmp_data_word_info[j].StartsWith("TestResult:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("TestResult:", ""); restult = restult.Replace("]", ""); tmp_data.setTestResult(bool.Parse(restult)); } } tmp_dataList.Add(tmp_data); } return tmp_dataList; }
private DataStruct[] string_fliter(String source) { String tmp_data = source; string restult = ""; String[] tmp_data_word_info = null; String[] tmp_data_word = tmp_data.Split('{'); DataStruct[] data = new DataStruct[tmp_data_word.Length - 1]; for (int i = 0; i < data.Length;i++) { data[i] = new DataStruct(); } for (int i=1; i<tmp_data_word.Length; i++) { tmp_data_word_info = tmp_data_word[i].Split('['); for (int j=1; j<7; j++) { if (tmp_data_word_info[j].StartsWith("Unit:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("Unit:", ""); restult = restult.Replace("]", ""); if (restult != "") { try { data[i - 1].setUnit(Int32.Parse(restult)); } catch { MessageBox.Show("Unit is not a number"); break; } } } else if (tmp_data_word_info[j].StartsWith("EnglishWord:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("EnglishWord:", ""); restult = restult.Replace("]", ""); data[i - 1].setEnglishWord(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord1:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord1:", ""); restult = restult.Replace("]", ""); data[i - 1].setChineseWord1(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord2:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord2:", ""); restult = restult.Replace("]", ""); data[i - 1].setChineseWord2(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord3:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord3:", ""); restult = restult.Replace("]", ""); data[i - 1].setChineseWord3(restult); } else if (tmp_data_word_info[j].StartsWith("ChineseWord4:") && tmp_data_word_info[j].EndsWith("]")) { restult = tmp_data_word_info[j].Replace("ChineseWord4:", ""); restult = restult.Replace("]", ""); data[i - 1].setChineseWord4(restult); } } } return data; }