i'm little struggling to find solution of this. How can i remove first word from string like my strings below.
"i am going to school"
"he is going to school"
"she is going to school"
"they are going to school"
so string can be any string and don't know about exact length of first word.but just want to remove first word.
The result should be like below
"am going to school"
"is going to school"
"is going to school"
"are going to school"
Any help?
Thanks
Overview. The chr method removes the first character of a string in Ruby. It removes the one-character string at the beginning of a string and returns this character.
In Ruby, we can permanently delete characters from a string by using the string. delete method. It returns a new string with the specified characters removed.
In Ruby, we can use the built-in chr method to access the first character of a string. Similarly, we can also use the subscript syntax [0] to get the first character of a string. The above syntax extracts the character from the index position 0 .
You can use Array. delete_at(0) method which will delete first element.
"i am going to school".split(' ')[1..-1].join(' ')
=> "am going to school"
You can go both ways in an array in ruby so -1 is the last element.
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