Odd word problem: Difference between revisions
Content deleted Content added
Reverse String function refactored for efficiency |
|||
Line 1,015: | Line 1,015: | ||
local fn ReverseString( string as CFStringRef ) as CFStringRef |
local fn ReverseString( string as CFStringRef ) as CFStringRef |
||
NSInteger i, length = len(string) |
|||
CFMutableStringRef mutStr = fn MutableStringWithString( string ) |
|||
for i = 0 to length - 1 |
|||
CFStringRef chr1 = mid( string, i, 1 ) |
|||
CFStringRef chr2 = mid( string, length-i-1, 1 ) |
|||
mid( mutStr, i, 1 ) = chr2 |
|||
CFStringRef chr1 = fn StringSubstringWithRange( string, range1 ) |
|||
mid( mutStr, length-i-1, 1 ) = chr1 |
|||
CFStringRef chr2 = fn StringSubstringWithRange( string, range2 ) |
|||
⚫ | |||
swap chr1, chr2 |
|||
MutableStringReplaceCharacters( mutStr, chr1, range1 ) |
|||
MutableStringReplaceCharacters( mutStr, chr2, range2 ) |
|||
⚫ | |||
end fn = mutStr |
end fn = mutStr |
||
Line 1,056: | Line 1,053: | ||
print fn OddWordTask( @"what,is,the;meaning,of:life." ) |
print fn OddWordTask( @"what,is,the;meaning,of:life." ) |
||
print fn OddWordTask( @"we,are;not,in,kansas;any,more." ) |
print fn OddWordTask( @"we,are;not,in,kansas;any,more." ) |
||
NSLog( @"%@", fn WindowPrintViewString( 1 ) ) |
|||
HandleEvents |
HandleEvents |