Unique characters in each string: Difference between revisions

FutureBasic solution added
(FutureBasic solution added)
Line 407:
<pre>
123abc
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
local fn StringCharacterIsUnique( string as CFStringRef, chr as CFStringRef ) as BOOL
long count = 0, length = len(string)
CFRange range = fn StringRangeOfString( string, chr )
while ( range.location != NSNotFound )
count++
range.location++
range = fn StringRangeOfStringWithOptionsInRange( string, chr, 0, fn CFRangeMake(range.location,length-range.location) )
wend
end fn = (count == 1)
 
void local fn DoIt
CFArrayRef strings = @[@"1a3c52debeffd",@"2b6178c97a938stf",@"3ycxdb1fgxa2yz"]
CFStringRef chr
CFMutableArrayRef array = fn MutableArrayWithCapacity(0)
long i, j, count, length = len(strings[0])
for i = 0 to length - 1
chr = mid(strings[0],i,1)
if ( fn StringCharacterIsUnique( strings[0], chr ) )
count = 1
for j = 1 to len(strings) - 1
if ( fn StringCharacterIsUnique( strings[j], chr ) )
count++
end if
next
if ( count == len(strings) ) then MutableArrayAddObject( array, chr )
end if
next
MutableArraySortUsingSelector( array, @"compare:" )
print fn ArrayComponentsJoinedByString( array, @" " )
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
1 2 3 a b c
</pre>
 
416

edits