hl

Thursday, 30 March 2017

Ruby Programming Language Tutorials Lec 12

Tutorial 12 : Cont. to strings

Equality in Strings 

     For equality in strings we are to simply write in double quote and we write a string and then write . operator and after that write equal and the put a question mark there and then write the equal string which you want to be equal in double quote. Let's check it out

                           Input                                                          Output
And if we write first_name.equal?first_name it will give result true because they are the exactly same objects.

Changing uppercase Lowercase and Swapcase

     To change a string in uppercase type the name of the string and write .upcase it will convert the whole string to the uppercase. Similarly for the lowercase and for the swapcase write downcase and swapcase. So let's check it out

             Input                                                            Output

 

Manipulation With Spaces in a String

If we added some extra spaces on the left side of a string or the right side of a string and it is taking some extra space in our memory so here we can swipe the white spaces by typing string name.lstrip for left removal of the white spaces .rstrip for right removal of blank spaces and .strip for clear all the blank spaces present in the string


Use of suffix and prefix

If you want to use some prefix you can do it with the use of just operator . I am telling you how to do it. It is quite simple by looking at this you will know how to do this.

                   Input                                  Output

No comments:

Post a Comment