Jump to content

Selectively replace multiple instances of a character within a string: Difference between revisions

no edit summary
No edit summary
Line 177:
<pre>abracadabra -> AErBcadCbFD
caaarrbabad -> cABarFECbDd</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
void local fn DoIt
long a = 0, b = 0, r = 0, length, i
CFMutableStringRef string = fn MutableStringWithString( @"abracadabra" )
CFStringRef s
length = len(string)
for i = 0 to length - 1
s = NULL
select ( mid(string,i,1) )
case @"a"
a++
select ( a )
case 1 : s = @"A"
case 2 : s = @"B"
case 4 : s = @"C"
case 5 : s = @"D"
end select
case @"b"
b++
if ( b == 1 ) then s = @"E"
case @"r"
r++
if ( r == 2 ) then s = @"F"
end select
if ( s ) then mid(string,i,1) = s
next
NSLog(@"%@",string)
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
AErBcadCbFD
</pre>
 
=={{header|Go}}==
416

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.