I have a string c1234
-- what's the most efficient and quick way to remove the first letter of a string?
The idea is to use the deleteCharAt() method of StringBuilder class to remove first and the last character of a string. The deleteCharAt() method accepts a parameter as an index of the character you want to remove.
Strings are immutable in JavaScript. Alternatively, you can use the slice() method. Use the String. slice() method to remove the first N characters from a string, e.g. const result = str.
1. Combine RIGHT and LEN to Remove the First Character from the Value. Using a combination of RIGHT and LEN is the most suitable way to remove the first character from a cell or from a text string. This formula simply skips the first character from the text provided and returns the rest of the characters.
Use slice!
:
s = "Hello"
s.slice!(0) #=> "ello"
Try it in an irb
:
ruby-1.9.3-p0 :001 > s = "Hello"
=> "Hello"
ruby-1.9.3-p0 :002 > s.slice!(0) #=> "ello"
=> "H"
ruby-1.9.3-p0 :003 > s
=> "ello"
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