How can I delete the last two characters 05
of the simple string?
Simple:
"apple car 05"
Code
String[] lineSplitted = line.split(":");
String stopName = lineSplitted[0];
String stop = stopName.substring(0, stopName.length() - 1);
String stopEnd = stopName.substring(0, stop.length() - 1);
orginal line before splitting ":"
apple car 04:48 05:18 05:46 06:16 06:46 07:16 07:46 16:46 17:16 17:46 18:16 18:46 19:16
Use the String. substring() method to remove the last 2 characters from a string, e.g. const removedLast2 = str. substring(0, str. length - 2); .
Use the String. substring() method to remove the last 3 characters from a string, e.g. const withoutLast3 = str. substring(0, str. length - 3); .
C# String. Remove() method has two overloaded forms: Remove(Int32) - Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted.
Subtract -2
or -3
basis of removing last space also.
public static void main(String[] args) {
String s = "apple car 05";
System.out.println(s.substring(0, s.length() - 2));
}
Output
apple car
Use String.substring(beginIndex, endIndex)
str.substring(0, str.length() - 2);
The substring begins at the specified beginIndex and extends to the character at index (endIndex - 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With