How to resolve the algorithm Strip a set of characters from a string step by step in the FreeBASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Strip a set of characters from a string step by step in the FreeBASIC programming language

Table of Contents

Problem Statement

Create a function that strips a set of characters from a string.

The function should take two arguments:

The returned string should contain the first string, stripped of any characters in the second argument:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Strip a set of characters from a string step by step in the FreeBASIC programming language

Source code in the freebasic programming language

' FB 1.05.0 Win64

Function stripChars(s As Const String, chars As Const String) As String
  If s = "" Then Return ""
  Dim count As Integer = 0
  Dim strip(0 To Len(s) - 1) As Boolean
  For i As Integer = 0 To Len(s) - 1
    For j As Integer = 0 To Len(chars) - 1
      If s[i] = chars[j] Then 
        count += 1
        strip(i) = True
        Exit For 
      End If
    Next j
  Next i

  Dim buffer As String = Space(Len(s) - count)
  count  = 0  
  For i As Integer = 0 To Len(s) - 1
    If Not Strip(i) Then
      buffer[count] = s[i]
      count += 1
    End If
  Next
  Return buffer
End Function

Dim s As String = "She was a soul stripper. She took my heart!"
Dim chars As String = "aei"
Print stripChars(s, chars)
Print
Print "Press any key to quit"
Sleep

  

You may also check:How to resolve the algorithm System time step by step in the EasyLang programming language
You may also check:How to resolve the algorithm 9 billion names of God the integer step by step in the Rust programming language
You may also check:How to resolve the algorithm Range expansion step by step in the Tailspin programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the Octave programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the Swift programming language