urjit on rails
urjit on rails

Reputation: 1893

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

Please help me.

Upvotes: 0

Views: 6670

Answers (3)

Rohit Siddha
Rohit Siddha

Reputation: 459

you can use gsub multiple times :

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

or use gsub! to change the original string like -

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

Upvotes: 1

sawa
sawa

Reputation: 168091

Do this:

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

Upvotes: 2

Marek Lipka
Marek Lipka

Reputation: 51151

You can do:

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

Upvotes: 6

Related Questions