Convert to Ruby Leet string

Introduction

This is a learning memo.

What is Leet?

For example, when the word "Warez" is written in leet, some alphabets are changed to numbers and symbols with similar shapes, such as "W @ rez" and "W4r3z".

This time, convert as follows in Ruby.

Alphabet ⇄ symbol conversion table
Alphabet symbol
A
B
C
D
E

Convert characters with Leet for the input character string. After that, the character string is output.

code

word = gets.chomp.split('')
word.each do |w|
  case w
  when 'A'
    print '6'
  when 'B'
    print '8'
  when 'C'
    print '5'
  when 'D'
    print '3'
  when 'E'
    print '1'
  else
    print w
  end
end

Input example

ABKTED

[Execution result]

68KT13

Commentary

word = gets.chomp.split('')

-In the first line, the input characters are separated one by one into an array and assigned to the word variable. gets method: Receives input as a "character string" line by line. chomp method: Removes line breaks in character strings. split method: Splits a character string into an array.

word.each do |w|

-Assign the element of the word variable to the w variable From the second line onward, match judgment and character replacement are performed character by character depending on the case.

Recommended Posts

Convert to Ruby Leet string
Convert String type to Timestamp type
Convert ruby object to JSON format
I want to convert InputStream to String
Convert iso-2022-jp character string to utf-8
Introduction to Ruby 2
Convert numbers to Roman numerals in Ruby
[Java] Convert Object type null to String type
Convert JSON to TSV and TSV to JSON with Ruby
[Ruby] How to convert from lowercase to uppercase and from uppercase to lowercase
Convert to a tag to URL string in Rails
Convert from C String pointer to Swift String type
Convert a string to a character-by-character array with swift
[Ruby] How to generate a random alphabet string
Ruby How to convert between uppercase and lowercase
URL to String conversion
From Java to Ruby !!
Leet string conversion program
Various Ruby string operations
<java> Read Zip file and convert directly to string
Sample code to convert List to List <String> in Java Stream
Ruby Regular Expression Extracts from a specific string to a string
[Kotlin] Convert ZonedDateTime to String by specifying the format
Convert Java Powerpoint to XPS
I want to convert characters ...
How to use Ruby return
Convert a Java byte array to a string in hexadecimal notation
How to change a string in an array to a number in Ruby
Convert Serializable Object to byte []
[Java] How to convert a character string from String type to byte type
[Ruby] How to comment out
How to use String [] args
[Ruby] Introduction to Ruby Error statement
Convert from ○ months to ○ years ○ months
Rbenv command to use Ruby
Ruby: How to use cookies
Ruby Learning # 8 Working With String
I tried to convert a string to a LocalDate type in Java
[Ruby] How to write blocks
How to convert Java radix
[Java] Convert ArrayList to array
Cut out a Ruby string
Explanation about Ruby String object
[Ruby] How to batch convert strings in an array to numbers
[Ruby] I want to put an array in a variable. I want to convert to an array
[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type
[Java] How to convert from String to Path type and get the path
Convert formulas to reverse Polish notation
Convert alphabet to 26 base + array length
Convert Map <K, V1> to Map <K, V2> (Convert Map Value)
[Ruby] Method to count specific characters
How to iterate infinitely in Ruby
Try to implement Yubaba in Ruby
How to install ruby through rbenv
How to use Ruby on Rails
Convert Markdown to HTML with flexmark-java
How to convert erb file to haml
Introduction to Ruby processing system self-made
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
String output method memo in Ruby