Reputation: 1639
How would I make this a regular string with no slash?
I have:
"3e265629c7ff56a3a88505062dd526bd\""
I want:
"3e265629c7ff56a3a88505062dd526bd"
Upvotes: 4
Views: 7493
Reputation: 160631
Ruby's String#[]
is your friend. Starting with:
foo = "3e...bd\""
These are alternate ways to get the value without the trailing embedded quote:
# delete it
foo[-1] = ''
foo['"'] = ''
foo[/"$/] = ''
Or:
# skip it
foo[0..-2]
Upvotes: 1
Reputation: 542
If you want to delete everything except letters and numbers you can use 'tr' function.
For example:
"3e265629c7ff56a3a88505062dd526bd\"".tr('^A-Za-z0-9','')
This function replace everything but letters and numbers with a string with no characters. Here is a reference of the function.
Hope it works for you.
Upvotes: 3
Reputation: 118299
How is this?
s = "3e265629c7ff56a3a88505062dd526bd\""
s[/\w+/]
# => "3e265629c7ff56a3a88505062dd526bd"
Upvotes: 5
Reputation: 19145
str = "3e265629c7ff56a3a88505062dd526bd\""
str.gsub(%r{\"}, '')
=> "3e265629c7ff56a3a88505062dd526bd"
Upvotes: 1
Reputation: 211740
What you have:
"3e265629c7ff56a3a88505062dd526bd\""
Is equivalent to:
'3e265629c7ff56a3a88505062dd526bd"'
So to remove that:
string.tr!('"', '')
Remember all special characters are prefixed with backslash. This includes not only things like newline \n
or linefeed \r
, but also quotation mark "
or backslash itself \\
.
Upvotes: 9