Answer to Question #295516 in HTML/JavaScript Web Application for chethan

Question #295516

given myString, startString and endString as inputs

your task is to get slice from the myString starting from the startString to the endString and log the sliced string in the console.


the output should be contain sliced string including the startString but not end string


input1

Buckjumping

j

i

output1

jump


"use strict";


process.stdin.resume();

process.stdin.setEncoding("utf-8");


let inputString = "";

let currentLine = 0;


process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});


process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});


function readLine() {

 return inputString[currentLine++];

}


function main() {

 const myString = readLine();

 const startString = readLine();

 const endString = readLine();


/* Please do not modify anything above this line */


 // Write your code here


}


1
Expert's answer
2022-02-09T13:08:29-0500
"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
	inputString += inputStdin;
});

process.stdin.on("end", (_) => {
	inputString = inputString.trim().split("\n").map((str) => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	const myString = readLine();
	const startString = readLine();
	const endString = readLine();

/* Please do not modify anything above this line */

 // Write your code here

 let start_index = myString.indexOf(startString);
 let end_index = myString.indexOf(endString);
 console.log(myString.slice(start_index, end_index));
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS