RosettaCodeData/Task/Strip-control-codes-and-extended-characters-from-a-string/FutureBasic/strip-control-codes-and-extended-characters-from-a-string.basic
2025-02-27 18:35:13 -05:00

47 lines
1.6 KiB
Text

include "NSLog.incl"
local fn StringStripControlCodes( string as CFStringRef ) as CFStringRef
CFMutableCharacterSetRef set = fn MutableCharacterSetNew
MutableCharacterSetAddCharactersInRange( set, fn CFRangeMake( 0, 32 ) )
MutableCharacterSetAddCharactersInRange( set, fn CFRangeMake( 127, 1 ) )
end fn = fn ArrayComponentsJoinedByString( fn StringComponentsSeparatedByCharactersInSet( string, set ), @"" )
local fn StringStripExtendedCharacters( string as CFStringRef ) as CFStringRef
CFCharacterSetRef set = fn CharacterSetWithRange( fn CFRangeMake( 128, 128 ) )
end fn = fn ArrayComponentsJoinedByString( fn StringComponentsSeparatedByCharactersInSet( string, set ), @"" )
void local fn DoIt
CFStringRef s1 = @"Welcome "
CFStringRef s2 = @"to "
CFStringRef s3 = @"FutureBasic"
CFMutableStringRef string = fn MutableStringWithString( s1 )
int i
for i = 0 to 31
MutableStringAppendString( string, ucs(i) )
next
MutableStringAppendString( string, ucs(127) )
MutableStringAppendString( string, s2 )
for i = 128 to 255
MutableStringAppendString( string, ucs(i) )
next
MutableStringAppendString( string, s3 )
NSLog(@"-- String --\n%@",string)
CFStringRef string1 = fn StringStripControlCodes( string )
NSLog(@"\n\n-- Control codes stripped --\n%@",string1)
CFStringRef string2 = fn StringStripExtendedCharacters( string )
NSLog(@"\n\n-- Extended characters stripped --\n%@",string2)
CFStringRef string3 = fn StringStripControlCodes( string )
string3 = fn StringStripExtendedCharacters( string3 )
NSLog(@"\n\n-- Control codes and extended characters stripped --\n%@",string3)
end fn
fn DoIt
HandleEvents