A
A
aaltw2021-08-05 17:20:57
ruby
aaltw, 2021-08-05 17:20:57

How to add a new value to a string by pattern?

There is a line: It is necessary to turn it into the following: How to do this optimally? Did it like this:
my_str = "a, b, c, d, e"

my_str = "'%a%', '%b%', '%c%', '%d%', '%e%'"


a = a
  .split(', ')
  .map{ |e| e = "'%"+e+"%'" }
  .join(', ')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-08-05
@altw

str.gsub(/\w+/, '\'%\0%\'')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question