Ruby | Symbol slice function
Last Updated :
10 Dec, 2019
Symbol#slice() : slice() is a Symbol class method which slices the symbol object and return the character value.
Syntax: Symbol.slice()
Parameter: Symbol values
Return: slices the symbol object and return the character value.
Example #1 :
a = :aBcDeF
b = : "\u{e4 f6 fc}"
c = : ABCDEF
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
puts "Symbol a slice form : #{a.slice(1)}\n\n"
puts "Symbol b slice form : #{b.slice(1)}\n\n"
puts "Symbol c slice form : #{c.slice(3)}\n\n"
|
Output :
Symbol a : aBcDeF
Symbol b : äöü
Symbol c : ABCDEF
Symbol a slice form : B
Symbol b slice form : ö
Symbol c slice form : D
Example #2 :
a = :geeks
b = : "\u{e5 f6 f3}"
c = : GEEKS
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
puts "Symbol a slice form : #{a.slice(1)}\n\n"
puts "Symbol b slice form : #{b.slice(1)}\n\n"
puts "Symbol c slice form : #{c.slice(3)}\n\n"
|
Output :
Symbol a : geeks
Symbol b : åöó
Symbol c : GEEKS
Symbol a slice form : e
Symbol b slice form : ö
Symbol c slice form : K
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...