ruby - 使用 .include 忽略字符串中的大小写?
问题描述
在这个程序中:
thisstring = "sample text"
if thisstring.include? "sample TEXT"
puts "heres some output"
end
有没有办法可以在这里使用 casecmp 来忽略 TEXT 中的大写字母?
解决方案
那这个呢?
if thisstring.downcase.include?("sample TEXT".downcase)
puts "heres some output"
end
或者:
if thisstring.match?(/#{sample TEXT}/i)
puts "heres some output"
end
推荐阅读
- python-2.7 - OS X:python 2.7.X 的多个版本
- c++ - static_cast 不起作用
- smartgwt - 以编程方式显示 ExpansionComponent
- gradle - 无法解析“/home/marcin/Projects/EduKotlinAcademy/web/build/node_modules_imported/kotlinx-html-js”中的“kotlin”
- node.js - 如果 nodejs 是旧版本,NPM init 在我的本地机器上会失败吗?
- javascript - Firebase 数据库规则不起作用
- php - 我无法将图像添加到广告恢复服务器
- git - 如何使用 git archive 从特定分支获取单个文件?
- html - 如何阻止 div 内并排的 3 个图像从换行到下一行?
- java - 从 ArrayList 中删除所有某些字符