Example: "[12,23,987,43"
What is the fastest, most efficient way to remove the "[" ?
Like, maybe a chop() but for the first char.
Example: "[12,23,987,43"
What is the fastest, most efficient way to remove the "[" ?
Like, maybe a chop() but for the first char.
Easy way:
str = "[12,23,987,43"
removed = str[1..str.length]
Awesome way:
class String
def reverse_chop()
self[1..self.length]
end
end
"[12,23,987,43".reverse_chop()
(Note: prefer the easy way :) )
If you always want to strip leading brackets:
"[12,23,987,43".gsub(/^\[/, "")
If you just want to remove the first character, and you know it won't be in a multibyte character set:
"[12,23,987,43"[1..-1]
or
"[12,23,987,43".slice(1..-1)
I kind of favor using something like:
asdf = "[12,23,987,43" asdf[0] = '' p asdf # >> "12,23,987,43"
Similar to Pablo's answer above, but a shade cleaner :
str[1..-1]
Will return the array from 1 to the last character.
'Hello World'[1..-1]
=> "ello World"