Str sub substring because it ensures that the substring will definitely be removed only from the beginning.
Ruby remove characters from string.
And using a regex like this would be better.
A string object holds and manipulates an arbitrary sequence of bytes typically representing characters.
Ruby strings cheat sheet of all shortcuts and commands.
Write a ruby program to get a substring from a specified position to the last char of a given string.
They let you use escaped control chars like n to represent their true value in this case newline and allow the use of expression so you can weave variables and well pretty much any ruby expression you like into the text.
Here str is the given string and parameter list are the specified characters.
Contribute your code and comments through disqus.
Write a ruby program to trim specific characters from a string.
How to remove the last character from a string.
Because of aliasing issues users of strings should be aware of the methods that modify the contents of a string object.
You need to use n not n in your gsub.
If you are asking the user for some input using the kernel gets method then you will have a newline character n at the end of your string this prevents you from comparing the string directly.
Delete is a string class method in ruby which is used to return a copy of the given string with all characters in the intersection of its arguments deleted.
It is used with functions such as the gets function and is used to remove the ending n character from the string obtained via the gets function.
Double quotes allow character expansion and expression interpolation ie.
A new copy of the string with all characters in the intersection of its arguments deleted.
The chomp function helps remove the trailing newline character ie n from any string.
Iterate over characters of a string in ruby.
Sub would be more appropriate than gsub since the op only wants to remove the substring from the beginning of the string not all through the string look at his sample code.
String objects may be created using new or as literals.
Ruby strings have many built in methods that make it easy to modify and manipulate text a common task in many programs.
The different quote marks behave differently.