hi folks googling 1 more hours.i did not find relevant, have text file this
s.no code l description interaction text 1 xxxx x xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2 xxxxxx x xxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx 3 xxxx x xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx 4 xxxxx x xxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 5 xxxxxx x xxxxxxxxxxxxxxx xxxxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxx xxxxx 6 xxxxxx x xxxxxxxxxxxxxxxx xxxxxxxx xxxxx xxxxxxx xxxxxxxxxx xxxxxxxx xxxxxxx
i reading contents using code,
string path = @"c:\temp\mytest.txt"; string[] lines = file.readalllines(path);
but stuck when split columns.any appreciated
in short
how split every columns using fixed length of string?
going cut example save time:
s.no code 1 xxxx x 2 xxxxxx x 3 xxxx x 4 xxxxx x 5 xxxxxx x 6 xxxxxx x
first define max lengths of each column, in example:
list<int> maxlengths = new list<int> { 2,7,4}; list<list<string>> columns = new list<list<string>>(); // we'll save columns
iterate on lines , use lengths know part of substring cut off:
foreach (string line in lines) { list<string> linescolumns = new list<string>(); int lastindex = 0; foreach (int maxlength in maxlengths) { linescolumns.add( line.substring(lastindex, maxlength)); lastindex += maxlength; } }
obviously simplified, you'll have work on error handling.
Comments
Post a Comment