Align columns: Difference between revisions

Content added Content deleted
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 4,009: Line 4,009:


local fn AlignColumn
local fn AlignColumn
NSUInteger i
'~'1
NSUInteger i
CFStringRef testStr = @"Given$a$text$file$of$many$lines,$where$fields$within$a$line$are$delineated$by¬

$a$single$'dollar'$character,$write$a$program$that$aligns$each$column$of$fields$by$ensuring$that$words¬
CFStringRef testStr = @"Given$a$text$file$of$many$lines,$where$fields$within$a$line$are$delineated$by¬
$in$each$column$are$separated$by$at$least$one$space.$Further,$allow$for$each$word$in$a$column$to$be¬
$a$single$'dollar'$character,$write$a$program$that$aligns$each$column$of$fields$by$ensuring$that$words¬
$either$left$justified$right$justified,$or$center$justified$within$its$column."
$in$each$column$are$separated$by$at$least$one$space.$Further,$allow$for$each$word$in$a$column$to$be¬
$either$left$justified$right$justified,$or$center$justified$within$its$column."
CFArrayRef temp = fn StringComponentsSeparatedByString( testStr, @"$" )

CFMutableArrayRef arr = fn MutableArrayWithArray( temp )
CFArrayRef temp = fn StringComponentsSeparatedByString( testStr, @"$" )
NSUInteger count = fn ArrayCount( arr )
CFMutableArrayRef arr = fn MutableArrayWithArray( temp )
ptr a(50)
NSUInteger count = fn ArrayCount( arr )
ptr a(50)
NSLog( @"\nLeft aligned:\n" )

NSUInteger lineCheck = 1
NSLog( @"\nLeft aligned:\n" )
for i = 0 to count -1
NSUInteger lineCheck = 1
a( lineCheck ) = (ptr)fn StringUTF8String( arr[i] )
for i = 0 to count -1
if ( lineCheck == 9 )
a( lineCheck ) = (ptr)fn StringUTF8String( arr[i] )
NSLog( @"%-12s %-11s %-12s %-11s %-12s %-12s %-12s %-12s %-12s", a(1),a(2),a(3),a(4),a(5),a(6),a(7),a(8),a(9) )
if ( lineCheck == 9 )
lineCheck = 1
NSLog( @"%-12s %-11s %-12s %-11s %-12s %-12s %-12s %-12s %-12s", a(1),a(2),a(3),a(4),a(5),a(6),a(7),a(8),a(9) )
else
lineCheck = 1
lineCheck++
else
end if
lineCheck++
next
end if
next
NSLog( @"\n\nRight aligned:\n" )

NSLog( @"\n\nRight aligned:\n" )
lineCheck = 1

for i = 0 to count -1
lineCheck = 1
a( lineCheck ) = (ptr)fn StringUTF8String( arr[i] )
for i = 0 to count -1
if ( lineCheck == 9 )
a( lineCheck ) = (ptr)fn StringUTF8String( arr[i] )
NSLog( @"%12s %11s %12s %11s %12s %12s %12s %12s %12s", a(1),a(2),a(3),a(4),a(5),a(6),a(7),a(8),a(9) )
if ( lineCheck == 9 )
lineCheck = 1
NSLog( @"%12s %11s %12s %11s %12s %12s %12s %12s %12s", a(1),a(2),a(3),a(4),a(5),a(6),a(7),a(8),a(9) )
else
lineCheck = 1
lineCheck++
else
end if
lineCheck++
next
end if
next

end fn
end fn


Line 4,077: Line 4,076:
justified right justified, or center justified within its column.
justified right justified, or center justified within its column.
</pre>
</pre>



=={{header|Gambas}}==
=={{header|Gambas}}==