[Solved] Remove the extra and not allowed characters from the ruby line


Here is my try as what I could understand from your question (Let me go through with your each sentences).

Your string:

s = "ggSuQNs6TxOTuQDd0j+4sA==$QO/Mq2jwfe3jgsGGoIGmlg==" 

Step-1

I need to transform it to
“ggSuQNs6TxOTuQDd0j4sAQOMq2jwfe3jgsGGoIGmlg” (Only letters and
numbers).

only characters and digits:

 > transform_string = s.tr('^A-Za-z0-9', '')
 #=> "ggSuQNs6TxOTuQDd0j4sAQOMq2jwfe3jgsGGoIGmlg" 

Step -2

Then trim it to 13 characters “ggSuQNs6TxOTu”

fetch first 13 characters like this way:

 > thirteen_chrs = transform_string[0..12]
 #=> "ggSuQNs6TxOTu" 

Step-3 (from your example)

number = 3242 

Step-4

after 3 characters the first half number of digits, paste after 9
characters second half number of digits.

here is in-line code for same:

> thirteen_chrs.insert(3, number.to_s.chars.each_slice(2).map(&:join).first).insert(9, number.to_s.chars.each_slice(2).map(&:join).last)
#=> "ggS3232uQ42Ns6TxOTu" 

I hope this may help you 🙂

solved Remove the extra and not allowed characters from the ruby line