2007-05-17 文字列の先頭と末尾の空白を削除する ruby string str = " abcXYZdefABCasfgYAb " p str.sub(/^\s+/, "").sub(/\s+$/, "") # 正規表現 p str.strip() # 専用命令