Answer to Question #176162 in HTML/JavaScript Web Application for mahidhar

Question #176162

String Slicing

Given two strings

inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.Input

  • The first line of input contains a string inputString
  • The second line of input contains a string subString

Output

  • The output should be a sliced string or inputString (if the inputString does not include the subString)

Sample Input 1

JavaScript

S

Sample Output 1

Script

Sample Input 2

Language

air

Sample Output 2

Language




"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();

});


 



Custom Input

RUN CODE

SUBMIT



1
Expert's answer
2021-04-01T15:59:06-0400
"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());

    let subString = 'S';
    let res = '';
    let index = inputString.indexOf(subString);

    if (index != -1) {
        res = inputString.slice(index)
    } else {
        res = inputString
    }

    main();
});

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