Answers for "remove first and last character from string in java"

3

java remove first character from string

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
Posted by: Guest on June-25-2020
0

How to remove the first and the last character of a string

//Here you go

var yourString = "/installers/";
var result = yourString.substring(1, yourString.length-1);

console.log(result);




//Or you can use .slice as suggested by Ankit Gupta

var yourString = "/installers/services/";

var result = yourString.slice(1,-1);

console.log(result);
Posted by: Guest on December-30-2020
0

remove first and last character from string in java

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);
Posted by: Guest on October-23-2021

Code answers related to "remove first and last character from string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language