0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

特定の文字列を検知するプログラムの練習

0
Posted at

check_nameメソッドをinclude?メソッドを用いて書こう。

・名前を入力すると「Your name has been registered」という文字列を出力する
・名前の中にアンダーバー(_)がある場合は、「 "エラーです。記号は登録できません"」という   文字列を出力する
・名前の中に空白(半角)がある場合は、「 "エラーです。空白は登録できません"」という文字列を出力する

こうなる。


def check_name(name) 
  if name.include?("_")
    puts "エラーです。記号は登録できません"
  elsif name.include?(" ")
    puts "エラーです。空白は登録できません"
  else
    puts "登録が完了しました♪"
  end
end
puts "登録したい名前を入力してください(例)FukuzawaYukichi"
name = gets
check_name(name) 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?