i reading text file values based on condition. first take freq cellid = 639 , ismainbcch=yes,that have done next task have concatenate freq values in comma separated way cellid=639 , ismainbcch=no, output want 24,28,67. how achieve that?
lines are
add gcell:cellid=639, cellname="nr_0702_07021_g1_a", mcc="424", mnc="02", lac=6112, ci=7021, ncc=6, bcc=0, exttp=normal_cell, iuotp=concentric_cell, eniuo=on, dbfreqbcchiuo=extra, flexmaio=off, csvsp=3, csdsp=5, pshpsp=4, pslpsvp=6, bspbcchblks=1, bspagblksres=4, bsprachblks=1, type=gsm900_dcs1800, ...................... ............. add gtrx:trxid=0, trxname="m_rak_jeerexch_g_1879_18791_a-0", freq=81, trxno=0, cellid=639, idtype=byid, ismainbcch=yes, istmptrx=no, gtrxgroupid=2556; add gtrx:trxid=1, trxname="m_rak_jeerexch_g_1879_18791_a-1", freq=24, trxno=1, cellid=639, idtype=byid, ismainbcch=no, istmptrx=no, gtrxgroupid=2556; add gtrx:trxid=5, trxname="m_rak_jeerexch_g_1879_18791_a-2", freq=28, trxno=2, cellid=639, idtype=byid, ismainbcch=no, istmptrx=no, gtrxgroupid=2556; add gtrx:trxid=6, trxname="m_rak_jeerexch_g_1879_18791_a-3", freq=67, trxno=3, cellid=639, idtype=byid, ismainbcch=no, istmptrx=no, gtrxgroupid=2556;
update
i getting values shown below
using (streamreader sr = file.opentext(filename)) { while ((s = sr.readline()) != null) { if (s.contains("add gcell:")) { var gtrx = new gtrx { cellid = int.parse(pullvalue(s, "cellid")), freq = int.parse(pullvalue(s, "freq")), trxno = int.parse(pullvalue(s, "trxno")), ismainbcch = pullvalue(s, "ismainbcch").toupper() == "yes", trxname = pullvalue(s, "trxname"), }; } }
update
i used facade concept, taking lot of time. not sure whether using bad logic 2 times iterating text file 1 getting regular values , other getting concatenated values
private class gtrx { public int freq { get; set; } public int trxno { get; set; } public string trxname { get; set; } public int cellid { get; set; } public bool ismainbcch { get; set; } } private class gcell { public int cellid { get; set; } public string cellname { get; set; } public string mcc { get; set; } public int lac { get; set; } public int ci { get; set; } } private class gcellgtrx { public gcell gcell { get; set; } public gtrx gtrx { get; set; } } using (var sr = new stringreader(data)) { string line = sr.readline(); while (line != null) { line = line.trim(); if (line.startswith("add gcell:")) { var gcell = new gcell { cellid = int.parse(pullvalue(line, "cellid")), cellname = pullvalue(line, "cellname"), ci = int.parse(pullvalue(line, "ci")), lac = int.parse(pullvalue(line, "lac")), mcc = pullvalue(line, "mcc") }; var gcellgtrx = new gcellgtrx(); gcellgtrx.gcell = gcell; _dictionary.add(gcell.cellid, gcellgtrx); } if (line.startswith("add gtrx:")) { var gtrx = new gtrx { cellid = int.parse(pullvalue(line, "cellid")), freq = int.parse(pullvalue(line, "freq")), trxno = int.parse(pullvalue(line, "trxno")), ismainbcch = pullvalue(line, "ismainbcch").toupper() == "yes", defined_tch_frq = null, trxname = pullvalue(line, "trxname") }; if (!intarr.contains(gtrx.cellid)) { if (!_dictionary.containskey(gtrx.cellid)) { // no gcell record id. something! continue; } intarr.add(gtrx.cellid); string results = string.empty; var result = string.join(",", ss in file.readlines(filename) ss.contains("add gtrx:") int.parse(pullvalue(ss, "cellid")) == gtrx.cellid pullvalue(ss, "ismainbcch").toupper() != "yes" select int.parse(pullvalue(ss, "freq"))); results = result; var gtrxnew = new gtrx { defined_tch_frq = results }; _dictionary[gtrx.cellid].gtrx = gtrx; } line = sr.readline(); } }
update
finally did first saved lines starting add gtrx in array using file. readalllines , used array concatenated string instead of storing entire text file , got performance improvement.
if convert text files contain hundreds of thousands of lines each xml , retrieve data xml file rather text file, make performance improvement? if use datatable , dataset rather classes here performance improvement?
create gtrxs
collection store gtrx
objects , read data file in gtrxs
. can use linq (ming need add using system.linq;
) find gtrx
objects matching requirements , call select
list of freq
values. once have list, can use string.join(",", freqvalues)
build csv string.
var gtrxs = new list<gtrx>(); using (streamreader sr = file.opentext(filename)) { while ((s = sr.readline()) != null) { if (s.contains("add gcell:")) { var gtrx = new gtrx { cellid = int.parse(pullvalue(s, "cellid")), freq = int.parse(pullvalue(s, "freq")), trxno = int.parse(pullvalue(s, "trxno")), ismainbcch = pullvalue(s, "ismainbcch").toupper() == "yes", trxname = pullvalue(s, "trxname"), }; gtrxs.add(gtrx); } } } ienumerable<int> freqvalues = gtrxs.where(x => x.cellid == 639 && x.ismainbcch == false).select(x => x.freq); string result = string.join(",", freqvalues);
Comments
Post a Comment