I need to split a string by the backslash, the problem is that when I have something like '\n' inside de string, it is not recognized. I found that this occurs because the double quoted string interprets the \n as a new line char.
example
irb(main):109:0> 'testestet\nehcucahu'.split('\\')
=> ["testestet", "nehcucahu"] # <---- this is what I want
irb(main):110:0> "testestet\nehcucahu".split('\\')
=> ["testestet\nehcucahu"]
Can I convert a double quoted string to a single quoted before calling split? Or there is another way achieve the desired behavior?
EDIT
Further work showed me that magento inserts a '\n' for every line on street, which make a lot more sense. I could split it on this specific situation using .split(/\n/). the comments below have better information if you need to split at a backslash
Aucun commentaire:
Enregistrer un commentaire