Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Im using ruby and rails to automatically create a filename from the name of the product and the product's variant-type. Using .gsub, the filename will be lowercase and have special characters (spaces, ', -) removed. Ive got most of it working but I can't seem to get it to remove double quotes.
This works for single quotes:
"'"
But this doesn't work for double-quotes:
'"'
Here's my code:
filepath_name = product.name+"_"+variant_type.gsub(/ /,'').gsub("'", "").gsub("-", "").gsub('"', '').downcase+".mpg"
You could just use a regexp to remove anything but ascii characters like:
variant_type.gsub!(/[^0-9A-Za-z.\-]/, '')
and modify it to suit your needs. You can use rubular for a reference.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a string from user input that is in the following format:
"foo\U+FFE2\U+FFB5\U+FFE2\U+FFB5"
When I view this it does not show anything in the browser or terminal, but they are definitely there.
What are they and how do I remove all junk chars like these to end up with just 'foo'?
I know I could just remove these specific ones but there maybe other different ones that I want just the text value from.
Any ideas?
I see the two main variants:
with #split/#join pair:
"fooффф".split('').select{|x|x.ord <= 127}.join
# => "foo"
with #unpack/#pack pair:
"fooффф".unpack('U*').select{|x| x <= 127}.pack('U*')
# => "foo"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am inserting some keyword like Don't , has'nt in Sqlite which is not inserted.any one have idea about it.
Use ' as escape character and insert it like this:
dont''t
Documentation:
A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal
In case you are using an API to connect with Sqlite, instead of manipulating the original string a better approach would be to use sqlite3_bind_text() function to bind a value to a ? placeholder in the SQL. Thanks to #Rob for pointing this out.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In my latex document I have use the tag \sout , to strike out some texts, in many places. Is there a one-shot way to delete the text in all the occurrences of the tag along with the tag ?
You could redefine the way \sout works by including the following in your document preamble:
\renewcommand{\sout}[1]{\unskip}
Here's an example illustrating the effect:
\documentclass{article}
\usepackage{ulem}% http://ctan.org/pkg/ulem
\begin{document}
Here is some \sout{text} stuff.
\renewcommand{\sout}[1]{\unskip}
Here is some \sout{text} stuff.
\end{document}
If you're using an editor that allows for searching with regular expressions, then you could do a find for the regular expression \\sout\{[^\}]+\} (note that this is untested) and replace with an empty string or space.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am trying to write a code inside \code{} in .tex file.
I am eager to write
\code{
cat("\n I want to write like this!")
}
However, latex gives me ERROR message, saying that \n is undefined control sequence.
I also tried \code{$\n$} and \code{\\n}. Neither works.
(I also know that \n works in verbatim environment. But I HAVE TO use \code{})
You can try this..
\textbackslash n
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need a regular expression for my Ruby on Rails application for the password field.
Any character or number or symbols is allowed except space.
If this is client-side validation in Javascript (or any language other than Ruby), this expression will match a string with no whitespace (\S) at least one character (+), no max:
^\S+$
Ruby is the only language that uses multi-line mode by default, so the start-of-line ^ and end-of-line $ behave differently (they match once per input, no matter how many lines). So, if you are validating the input in Ruby, you'd need to use \A for start-of-line and \Z for end-of-line.
\A\S+\Z
All except spaces, do you need to narrow the results a bit more than this?
/[^ ]+/
This is without minimum length (or rather, with minimum length 1):
^\S+$
With minimum length 8:
^\S{7}\S+$
or, if your regex engine supports it (don't know why it wouldn't):
^\S{8,}$