columns in a text file

From: red (groups2_at_reenie.org)
Date: 01/30/05


Date: Sun, 30 Jan 2005 19:18:53 GMT

I have two columns of strings of various lengths.
I want the second column to be straight, so I need to find the correct
number of tabs between the two columns for each row.I don't mind
starting with a wide column with a preset number of tabs and adjusting
it statically to fit my data, so I don't need to get the length of the
longest string in the first column before I start.

Through trial and error, I have an algorithm that seems to work. There's
a pattern in there but I don't see the logic. Does anyone have a
more graceful algorithm for this, the way it should be done ?
for each row, I use this:

echo tabber($col1_value, 5);
echo col2_value;

function tabber($col1, $tabs=1){
   $result=$col1;
   $len=strlen($col1);
   if($len>28)$tabs+=1;
   if($len==22)$tabs+=1;
   if($len<1)$tabs-=1;
   if($len==7)$tabs-=1;
   for($i=$len; $i>0; $i=$i-7)
     $tabs=$tabs-1;
   for($j=1; $j<$tabs; $j++)
     $result.= "\t";
     // $result.="_".$len."_".$tabs."_";// adds debug info to column 2
     return $result;
}

red
                                



Relevant Pages

  • Re: Some notes
    ... tabs are not going to be allowed as indentation to Python code. ... > Keeping them in strings and comments is a non-issue. ... > typing isn't coming to CPython any time soon, probably not even for Py3k". ...
    (comp.lang.python)
  • Re: Regular Expression
    ... other space-like characters such as tabs, you'll have to modify this ... but it's also okay not to have them. ... I.e. are we allowing all strings, ...
    (comp.lang.java.programmer)
  • Re: replace
    ... Why do you think that your C# program doesn't think the strings are the same ... as those in the XML file? ... why do you think that Excel changes tabs to spaces? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need some help - PLEASE
    ... I change my formulas to strings, copy|paste, then change my strings back to ... It has 19 tabs on it. ... The 18th tab takes numbers from many multiple cells from the first 17 ... Anyway....I finally got the sheet the way I need it but here is my ...
    (microsoft.public.excel.misc)