简体   繁体   English

从 string rails 2 ruby​​ 1.9.2 中删除单引号和双引号 + 空格

[英]Remove single quote and double quote + white spaces from string rails 2 ruby 1.9.2

I have functionality to upload image and in that image if image name have any single quotes or double quotes or white space then I got error to uploaded at amazon我有上传图片的功能,如果图片名称有任何单引号或双引号或空格,那么我在亚马逊上传时出错

So how to remove wild characters and spaces from image name?那么如何去除图片名称中的通配符和空格呢?

Sorry one edit对不起一编辑
I need to add %20 in place of white space我需要添加 %20 代替空格

Please help me.请帮我。

你可以做:

string.gsub(/\s|"|'/, '')

做这个:

string.tr(" '\"", "")

you can use gsub multiple times :您可以多次使用 gsub :

string.gsub(/"|'/, '').gsub(/\s/, '%20')

or use gsub!或使用 gsub! to change the original string like -更改原始字符串,如 -

string.gsub!(/"|'/, '').gsub!(/\s/, '%20')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM