How to resolve the algorithm String interpolation (included) step by step in the QB64 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm String interpolation (included) step by step in the QB64 programming language

Table of Contents

Problem Statement

Given a string and defined variables or values, string interpolation is the replacement of defined character sequences in the string by values or variable values.

Note: The task is not to create a string interpolation routine, but to show a language's built-in capability.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm String interpolation (included) step by step in the QB64 programming language

Source code in the qb64 programming language

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$"

  

You may also check:How to resolve the algorithm Caesar cipher step by step in the Python programming language
You may also check:How to resolve the algorithm System time step by step in the Oforth programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the F# programming language
You may also check:How to resolve the algorithm 15 puzzle game step by step in the Simula programming language
You may also check:How to resolve the algorithm Classes step by step in the Tcl programming language