How to resolve the algorithm Strip block comments step by step in the XProfan programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Strip block comments step by step in the XProfan programming language

Table of Contents

Problem Statement

A block comment begins with a   beginning delimiter   and ends with a   ending delimiter,   including the delimiters.   These delimiters are often multi-character sequences.

Strip block comments from program text (of a programming language much like classic C). Your demos should at least handle simple, non-nested and multi-line block comment delimiters.
The block comment delimiters are the two-character sequences:

Sample text for stripping: Ensure that the stripping code is not hard-coded to the particular delimiters described above, but instead allows the caller to specify them.   (If your language supports them,   optional parameters   may be useful for this.)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Strip block comments step by step in the XProfan programming language

Source code in the xprofan programming language

Proc strip_block_comments
   Parameters string inhalt, beg_delim, end_delim
   Declare long start, ende, anzahl
   start = 1
   start = InStr(beg_delim, inhalt, start)
   While start > 0
      ende = InStr(end_delim, inhalt, start + len(beg_delim))
      If ende > 0
         anzahl = ende +  + len(end_delim) - start
         inhalt = Del$(inhalt, start, anzahl)
      Else
         BREAK
      EndIf
      start = InStr(beg_delim, inhalt, start)
   EndWhile
   Return inhalt
EndProc

Cls
Declare string Text
Text = BlockRead("C:\Temp\Multiline_comment.txt")
Text = strip_block_comments(Text, "/*", "*/")
Print "Output:"
Print Text
WaitKey
End

  

You may also check:How to resolve the algorithm Rename a file step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Xiaolin Wu's line algorithm step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Vala programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the Python programming language
You may also check:How to resolve the algorithm Nonoblock step by step in the Action! programming language