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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!