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

Content added Content deleted
(Selectively replace multiple instances of a character within a string in FreeBASIC)
Line 82: Line 82:
caaarrbabad -> cABarFECbDd
caaarrbabad -> cABarFECbDd
</pre>
</pre>

=={{header|FreeBASIC}}==
<lang freebasic>Function replaceChar(Byref S As String) As String
Dim As String A = "ABaCD", B = "Eb", R = "rF"
Dim As Byte pA = 1, pB = 1, pR = 1
For i As Byte = 0 To Len(S)
Select Case Mid(S,i,1)
Case "a"
Mid(S,i,1) = Mid(A,pA,1)
pA += 1
Case "b"
Mid(S,i,1) = Mid(B,pB,1)
pB += 1
Case "r"
Mid(S,i,1) = Mid(R,pR,1)
pR += 1
End Select
Next i
Return S
End Function

Dim As String S
S = "abracadabra"
Print S; " -> "; replaceChar(S)
S = "caarabadrab"
Print S; " -> "; replaceChar(S)
Sleep</lang>
{{out}}
<pre>abracadabra -> AErBcadCbFD
caaarrbabad -> cABarFECbDd</pre>


=={{header|Go}}==
=={{header|Go}}==