特別な文字を削除して表示。
設問
Write a program to remove specific characters from a string.
Input sample:
The first argument will be a text file containing an input string followed by a comma and then the characters that need to be scrubbed. e.g.
how are you, abc hello world, def
Output sample:
Print to stdout, the scrubbed strings, one per line. Trim out any leading/trailing whitespaces if they occur.
e.g.
how re you hllo worl
やってみた
#!/usr/bin/env ruby ARGF.lines do |line| main, removes = line.split(',').map(&:strip) puts removes.chars.inject(main){ |str, char| str.gsub(char, '') } end