1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

文字列の部分一致

文字列を部分一致するプログラムを紹介いたします

プログラム例

s = "test1"
n = 3
for i in 0...n
    r = gets.chomp!
    array1.push(r)
end

array1.each do |word|
    #配列array1から要素を1つずつword変数に取り出し、word変数の中に「test1」が含まれれば「Yes」、違う場合が「No」を出力する
    if word.include?(s)
        puts "Yes"
    else
        puts "No"
    end
end

ポイントは

[検索対象の文字列].include?(検索したい文字列)

です。

最後に

Rubyで文字列の部分一致について説明しました

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?