String string = "Hello World";
//Remove first character
string.substring(1); //ello World
//Remove last character
string.substring(0, string.length()-1); //Hello Worl
//Remove first and last character
string.substring(1, string.length()-1); //ello Worl
String roles = "[This is an example of list.toString()]";
//Below substring method will remove the first and last character of roles String
roles = roles.substring(1, roles.length()-1);
// here roles will become "This is an example of list.toString()"
System.out.println("New String: "+roles);
// Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters.
function removeChar(str){
const strLength = str.length
if(strLength < 2) return str
return str.substr(1, strLength - 2)
};
// With love @kouqhar
"Hello World".substring(1) // ello World
// Remove first and last letter of string
fn main() {
let text = "Hello, world";
// remove last letter
let mut text = text.split_at(text.len() - 1);
// remove first letter
text = text.0.split_at(1);
println!("{}", text.1);
}
Remove the first or last charachter of a String