Tutorial 11 : Strings
Multi line String
We make multi line string very easily. Just by typing "multiline_string" and it is end with = and two less than sign and after that type in capital EOM. Now your multiine string is start and inside it you can write very long string and in this we can do interpolation also like we can write # {4 + 5} and also give new line command by using \n. Let's do practically what I said to you. Check it from the below diagrams
Input Output
Manipulation with strings
Now I will tell you about the several type of string printing. Such as addition of 2 strings by + symbol and by interpolation and also learn about a new type of keyword include by which we can search a string into another string. This language is also very good for string purposes.
In this we are making a variable name First_name and give it a value Derek
and make another variable name last_name and give the value Banas.
In third line we make another variable name full_name and give them the value first_name + last_name. After that make another variable of name middle_name and its value Justin. Than we add all three strings into one string name full_name. At last we search Justin into full_string. and than it will give the result true
For taking the size of the string just write string_name.size and it will return the size of the string you can print it with the help of print or puts.
for the count of vowels we is to simply write the string_name,count("aeiou") it will return the count of the vowels present in the string .
For the count of consonants we is to simply write string_name.count("^aeiou"). It will return the count of the consonants present in the string.
For the string string start with in the "Banas" Just type string_name.start_with?("Banas")
will return in true or false.
For the indexing of the string just write string_name.index
for the count of vowels we is to simply write the string_name,count("aeiou") it will return the count of the vowels present in the string .
For the count of consonants we is to simply write string_name.count("^aeiou"). It will return the count of the consonants present in the string.
For the string string start with in the "Banas" Just type string_name.start_with?("Banas")
For the indexing of the string just write string_name.index
No comments:
Post a Comment