46 lines
1.3 KiB
Plaintext
46 lines
1.3 KiB
Plaintext
include "NSLog.incl"
|
|
|
|
local fn AlignColumn
|
|
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¬
|
|
$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 )
|
|
NSUInteger count = fn ArrayCount( arr )
|
|
ptr a(50)
|
|
|
|
NSLog( @"\nLeft aligned:\n" )
|
|
NSUInteger lineCheck = 1
|
|
for i = 0 to count -1
|
|
a( lineCheck ) = (ptr)fn StringUTF8String( arr[i] )
|
|
if ( lineCheck == 9 )
|
|
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) )
|
|
lineCheck = 1
|
|
else
|
|
lineCheck++
|
|
end if
|
|
next
|
|
|
|
NSLog( @"\n\nRight aligned:\n" )
|
|
|
|
lineCheck = 1
|
|
for i = 0 to count -1
|
|
a( lineCheck ) = (ptr)fn StringUTF8String( arr[i] )
|
|
if ( lineCheck == 9 )
|
|
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) )
|
|
lineCheck = 1
|
|
else
|
|
lineCheck++
|
|
end if
|
|
next
|
|
|
|
end fn
|
|
|
|
fn AlignColumn
|
|
|
|
HandleEvents
|