34 lines
1.1 KiB
Plaintext
34 lines
1.1 KiB
Plaintext
local fn MiddleThreeDigits( n as NSInteger ) as CFStringRef
|
|
CFStringRef testStr, resultStr
|
|
NSInteger length, middle
|
|
|
|
testStr = fn StringWithFormat( @"%ld", n )
|
|
testStr = fn StringByReplacingOccurrencesOfString( testStr, @"-", @"" )
|
|
length = len(testStr)
|
|
if length < 3 then resultStr = fn StringWithFormat( @"%10ld -> Error: Less than three digits.", n ) : exit fn
|
|
if length == 3 then resultStr = fn StringWithFormat( @"%10ld -> %@", n, testStr ) : exit fn
|
|
length = len(testStr)
|
|
if ( length mod 2 == 0 )
|
|
resultStr = fn StringWithFormat( @"%10ld -> Error: Even length; needs odd.", n )
|
|
else
|
|
middle = length / 2
|
|
resultStr = fn StringWithFormat( @"%10ld -> %@", n, mid( testStr, middle -1, 3 ) )
|
|
end if
|
|
end fn = resultStr
|
|
|
|
window 1, @"Middle Three Digits", ( 0, 0, 400, 300 )
|
|
|
|
NSUInteger i, count
|
|
CFArrayRef testArr
|
|
CFNumberRef tempNum
|
|
|
|
testArr = @[@123,@12345,@1234567,@987654321,@10001,@-10001,¬
|
|
@-123,@-100,@100,@-12345,@1,@2,@-1,@-10,@2002,@-2002,@0]
|
|
|
|
count = fn ArrayCount( testArr )
|
|
for i = 0 to count - 1
|
|
print fn MiddleThreeDigits( fn NumberIntegerValue( testArr[i] ) )
|
|
next
|
|
|
|
HandleEvents
|