Forum: Ruby on Rails how to replace special charracters

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rm R. (Guest)
on 2007-04-27 04:57
From the form input I have some data which is inserted into database ,
and this data may have some special characters which can cause problems
in other parts of the system. Now before inserting into db, how can I
replace those characters with acceptable chars? Is there a standard way
to replace double quotes with single quotes, slash with hyphen etc.?

Thanks.
Philip H. (Guest)
on 2007-04-27 06:05
(Received via mailing list)
> From the form input I have some data which is inserted into database ,
> and this data may have some special characters which can cause problems
> in other parts of the system. Now before inserting into db, how can I
> replace those characters with acceptable chars? Is there a standard way
> to replace double quotes with single quotes, slash with hyphen etc.?

Look into Tidy...

http://tidy.rubyforge.org/

-philip
Herryanto S. (Guest)
on 2007-04-27 06:54
(Received via mailing list)
If you are using it for db purpose, regarding the single quote issue,
you
can look at:

ActiveRecord::Base#sanitize_sql

Or a more flexible replacement, try 'gsub':

clean_string = "test".gsub(/[regex]/, '[replaced character]')
Monet B. (Guest)
on 2007-08-09 09:48

hello....

       if i have a string '12-34-56-78', how can i replace the '78' with
'91'...pls.....help...





thanks
This topic is locked and can not be replied to.