String Slicing
Given two strings
Check Whether the input string includes the substring using if condition and includes().
if the input string includes the substring then, find the index of the substring in the input string, using the indexof() and store the index in a variable.
slice the input string, using the slice() form index to the length of the input string and store in the variable slicedString. console the variable sliceString.
If the input string doesn't include the substring then else console the input string.
'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(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
const inputString = readLine();
const subString = readLine();
let index = aqString.find(inputString, subString);
if (isNaN(index) && index <= inputString.length) {
console.log(inputString.split(index));
}
}
Comments
Leave a comment