Tutorial 13 : Cont. to strings
Use of CHOP and CHOMP
To remove the last charecter from the string we use chop by typing string_name and then dot operator and then write chop. your last character is chopped out like if you want only first name in the full name so write full_name.chop the it will remove the last part from the full name
And the CHOMP work same as chop works but it delete multiple letters
Input Output
Delete
There is a keyword in ruby to delete a
letter in the whole string. Such as if you want to delete a letter from the
string full name you is to type full_name.delete(“a”) it will do delete the
letter a from the string. So let’s check it out
Example is below with split
Split
To split every letter in the string first
write name of the string and then write dot operator and the write split it
will do split the string but it is not full for every letter pass // in the parenthesis.
For split the words do the same but pass
the / /with space between them by which it will split the words out
Input Output
NOTE: It
will also count white spaces as a letter
No comments:
Post a Comment