RosettaCodeData/Task/Quoting-constructs/FreeBASIC/quoting-constructs.basic

32 lines
1.1 KiB
Plaintext

'In FB there is no substr function, then
'Function taken fron the https://www.freebasic.net/forum/index.php
Function substr(Byref soriginal As String, Byref spattern As Const String, Byref sreplacement As Const String) As String
' in <soriginal> replace all occurrences of <spattern> by <sreplacement>
Dim As Uinteger p, q
If sreplacement <> spattern Then
p = Instr(soriginal, spattern)
If p Then
q = Len(sreplacement)
If q = 0 Then q = 1
Do
soriginal = Left(soriginal, p - 1) + sreplacement + Mid(soriginal, p + Len(spattern))
p = Instr(p + q, soriginal, spattern)
Loop Until p = 0
End If
End If
Return soriginal
End Function
Dim As String text(1 To 3)
text(1) = "This is 'first' example for quoting"
text(2) = "This is second 'example' for quoting"
text(3) = "This is third example 'for' quoting"
For n As Integer = 1 To Ubound(text)
Print !"text for quoting:\n"; text(n)
Print !"quoted text:\n"; substr(text(n),"'",""); !"\n"
Next n
Sleep