How to resolve the algorithm Search in paragraph's text step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Search in paragraph's text step by step in the Wren programming language

Table of Contents

Problem Statement

The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within what I want to call "the paragraphs" "Traceback (most recent call last):" in the file Traceback.txt The expected result must be formated with ---------------- for paragraph's separator AND "Traceback (most recent call last):" as the beginning of each relevant's paragraph :

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Search in paragraph's text step by step in the Wren programming language

Source code in the wren programming language

import "io" for File
import "./pattern" for Pattern

var fileName = "Traceback.txt"
var p1 = Pattern.new("Traceback (most recent call last):")
var p2 = Pattern.new("SystemError")
var sep = "----------------"

File.read(fileName)
    .split("\n\n")
    .where { |para| p1.isMatch(para) && p2.isMatch(para) }
    .each { |para|
        var ix = p1.find(para).index
        System.print(para[ix..-1])
        System.print(sep)
    }

  

You may also check:How to resolve the algorithm Ackermann function step by step in the Z80 Assembly programming language
You may also check:How to resolve the algorithm Padovan n-step number sequences step by step in the C programming language
You may also check:How to resolve the algorithm Penney's game step by step in the VBA programming language
You may also check:How to resolve the algorithm Twelve statements step by step in the Perl programming language
You may also check:How to resolve the algorithm Brownian tree step by step in the Nim programming language