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";
function readLine() {
return inputString[currentLine++];
}
function main() {
let inputString = readLine();
const subString = readLine();
/* Write your code here */
console.log(subString.substr(inputString.substr(subString)));
}
function stringSlicing(inputString, subString) {
let index = inputString.indexOf(subString);
if (index != -1) {
return inputString.slice(index)
} else {
return inputString
}
}
console.log(stringSlicing('JavaScript', 'S'));
console.log(stringSlicing('Language', 'air'));
Comments
Leave a comment