How to resolve the algorithm Selectively replace multiple instances of a character within a string step by step in the FutureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Selectively replace multiple instances of a character within a string step by step in the FutureBasic programming language
Table of Contents
Problem Statement
This is admittedly a trivial task but I thought it would be interesting to see how succinctly (or otherwise) different languages can handle it. Given the string: "abracadabra", replace programatically:
Note that there is no replacement for the third 'a', second 'b' or first 'r'. The answer should, of course, be : "AErBcadCbFD".
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Selectively replace multiple instances of a character within a string step by step in the FutureBasic programming language
Source code in the futurebasic programming language
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
You may also check:How to resolve the algorithm Hash from two arrays step by step in the Ceylon programming language
You may also check:How to resolve the algorithm Palindromic gapful numbers step by step in the zkl programming language
You may also check:How to resolve the algorithm Queue/Usage step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Slate programming language
You may also check:How to resolve the algorithm Stirling numbers of the second kind step by step in the ALGOL W programming language