How to resolve the algorithm String matching step by step in the Oforth programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm String matching step by step in the Oforth programming language

Table of Contents

Problem Statement

Given two strings, demonstrate the following three types of string matching:

Optional requirements:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm String matching step by step in the Oforth programming language

Source code in the oforth programming language

: stringMatching(s1, s2)
| i |
   s2 isAllAt(s1, 1) ifTrue: [ System.Out s1 << " begins with " << s2 << cr ]
   s2 isAllAt(s1, s1 size s2 size - 1 + ) ifTrue: [ System.Out s1 << " ends with " << s2 << cr ] 

   s1 indexOfAll(s2) ->i
   i ifNotNull: [ System.Out s1 << " includes " << s2 << " at position : " << i << cr ]

   "\nAll positions : " println 
   1 ->i
   while (s1 indexOfAllFrom(s2, i) dup ->i notNull) [
      System.Out s1 << " includes " << s2 << " at position : " << i << cr
      i s2 size + ->i
      ] ;

  

You may also check:How to resolve the algorithm Roman numerals/Encode step by step in the Raku programming language
You may also check:How to resolve the algorithm Pell numbers step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Find common directory path step by step in the RPL programming language
You may also check:How to resolve the algorithm Queue/Definition step by step in the Prolog programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Computer/zero Assembly programming language