"~"で任意の文字を囲む方法
【概要】
1.結論
2.どのようにコーディングするか
3.開発環境
1.結論
gets.chomp、lengthメソッドを使用する!!
2.どのようにコーディングするか
str = gets.chomp #---❶
str_length = str.length
puts('~' * (str_length + 2)) #---❷
puts('~'+str+'~') #---❸
puts('~' * (str_length + 2)) #---❷
❶:.chompを入れないと下記のようになります。改行をして2行目の最後の"~"をくっつけています。
❷:lengthメソッドで入力したの文字の長さに +2しています。+2する理由は左上の"~"と右上の"~"の角っこを加えています。
❸:入力した文字の両端に"~”を加えています。
3.開発環境
Mac catalina 10.15.4
Vscode
Ruby 2.6.5
Rails 6.0.3.3
Author And Source
この問題について("~"で任意の文字を囲む方法), 我々は、より多くの情報をここで見つけました https://qiita.com/taka_no_okapi/items/493edc81e2333f63c51c著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .