String interpolation (included): Difference between revisions

Content added Content deleted
No edit summary
Line 692: Line 692:
PRINT "Mary had a "; x$; " lamb"
PRINT "Mary had a "; x$; " lamb"
x$ = "little"
x$ = "little"
PRINT USING "Mary also had a & lamb"; x$</lang>
PRINT USING "Mary also had a & lamb"; x$
' this code above doesn't modify the first string subsustituting a piece od it with another string
'surely it gives the right output on the screen</lang>


==={{header|True BASIC}}===
==={{header|True BASIC}}===
Line 1,675: Line 1,677:
'Mary had a little lamb.'
'Mary had a little lamb.'
>>> </lang>
>>> </lang>
=={{header|QB64}}==
<lang QB64>
DefStr S

' Qbasic /QuickBasic MID$ statement needs that string2 and substring
' to replace in string1 must have the same length,
' otherwise it overwrites the following part of string1
String1 = "Mary has a X lamb"
Print String1, "Original String1"
Print "Interpolation of string by MID$ statement"
String2 = "little"
Mid$(String1, InStr(String1, "X")) = String2
Print String1

String1 = "Mary has a X lamb"
String2 = "@"
Mid$(String1, InStr(String1, "X")) = String2
Print String1

Print "Interpolation by string's functions"
String1 = "Mary has a X lamb"
String2 = "little"
String1 = Mid$(String1, 1, InStr(String1, "X") - 1) + String2 + Mid$(String1, InStr(String1, "X") + 1, Len(String1) - InStr(String1, "X"))
Print String1, "by MID$"

String1 = "Mary has a X lamb"
String2 = "#§[]@"
String1 = Left$(String1, InStr(String1, "X") - 1) + String2 + Right$(String1, Len(String1) - InStr(String1, "X") + 1)
Print String1, "by LEFT$ and RIGHT$"

</lang>


=={{header|Racket}}==
=={{header|Racket}}==