`` inside a string does not escape anything
The character is used to escape some characters in a string. I need a string that includes
like this:
str = "Lucas Andrade "My name""
When I print str
, I should see this:
print str
# >> Lucas Andrade "My name"
I will embed this string directly inside a json param to send an API request using HTTParty like this example:
params {
"name": "Lucas",
"json": {
"address": "some",
"street": "example",
"string": "the custom "string""
}
}
I think HTTParty does not format this string automatically.
json ruby string
add a comment |
The character is used to escape some characters in a string. I need a string that includes
like this:
str = "Lucas Andrade "My name""
When I print str
, I should see this:
print str
# >> Lucas Andrade "My name"
I will embed this string directly inside a json param to send an API request using HTTParty like this example:
params {
"name": "Lucas",
"json": {
"address": "some",
"street": "example",
"string": "the custom "string""
}
}
I think HTTParty does not format this string automatically.
json ruby string
"inside a string does not escape anything" – not true, it escapes the
"
which would otherwise end the string.
– Stefan
Nov 21 '18 at 8:12
add a comment |
The character is used to escape some characters in a string. I need a string that includes
like this:
str = "Lucas Andrade "My name""
When I print str
, I should see this:
print str
# >> Lucas Andrade "My name"
I will embed this string directly inside a json param to send an API request using HTTParty like this example:
params {
"name": "Lucas",
"json": {
"address": "some",
"street": "example",
"string": "the custom "string""
}
}
I think HTTParty does not format this string automatically.
json ruby string
The character is used to escape some characters in a string. I need a string that includes
like this:
str = "Lucas Andrade "My name""
When I print str
, I should see this:
print str
# >> Lucas Andrade "My name"
I will embed this string directly inside a json param to send an API request using HTTParty like this example:
params {
"name": "Lucas",
"json": {
"address": "some",
"street": "example",
"string": "the custom "string""
}
}
I think HTTParty does not format this string automatically.
json ruby string
json ruby string
edited Nov 21 '18 at 6:15


sawa
131k29202301
131k29202301
asked Nov 20 '18 at 20:02


Lucas AndradeLucas Andrade
378416
378416
"inside a string does not escape anything" – not true, it escapes the
"
which would otherwise end the string.
– Stefan
Nov 21 '18 at 8:12
add a comment |
"inside a string does not escape anything" – not true, it escapes the
"
which would otherwise end the string.
– Stefan
Nov 21 '18 at 8:12
"
inside a string does not escape anything" – not true, it escapes the "
which would otherwise end the string.– Stefan
Nov 21 '18 at 8:12
"
inside a string does not escape anything" – not true, it escapes the "
which would otherwise end the string.– Stefan
Nov 21 '18 at 8:12
add a comment |
3 Answers
3
active
oldest
votes
I am not very fluent in Ruby, but this is commonly done with "\"
, resulting in ""
So, "Lucas Andrade \"My name\""
should result in what you're looking for, an escaped and an escaped
"
add a comment |
When you need to send the string as JSON to an API, why don't you use JSON.generate
to escape the string as needed?
JSON.generate("Lucas Andrade "My name"")
1
The OP should probably generate the whole JSON structure out of a Ruby hash.
– Stefan
Nov 21 '18 at 8:10
add a comment |
You can wrap it in single quote marks.
str = 'Lucas Andrade "My name"'
=> "Lucas Andrade "My name""
This does not answer the question. He needs the output to include the backslash character and the output ofputs 'Lucas Andrade "My name"'
does not include a backslash.
– anothermh
Nov 20 '18 at 20:27
There's a bit of confusion from OP: ` So when I print my str I should see this: "Lucas Andrade "My name""` which my answer does. But OP also says they want the backslash therein.
– well-i-better-get-rolling
Nov 20 '18 at 20:28
In rubyputs
andprint
are different, that's why I saidprint
. In your answer the are just represented by ruby output syntax, the are not part of the string.
– Lucas Andrade
Nov 20 '18 at 20:58
You're right. You did sayprint
.
– well-i-better-get-rolling
Nov 20 '18 at 21:13
puts
is likeprint
with newline (if missing).
– Stefan
Nov 21 '18 at 7:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400700%2finside-a-string-does-not-escape-anything%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am not very fluent in Ruby, but this is commonly done with "\"
, resulting in ""
So, "Lucas Andrade \"My name\""
should result in what you're looking for, an escaped and an escaped
"
add a comment |
I am not very fluent in Ruby, but this is commonly done with "\"
, resulting in ""
So, "Lucas Andrade \"My name\""
should result in what you're looking for, an escaped and an escaped
"
add a comment |
I am not very fluent in Ruby, but this is commonly done with "\"
, resulting in ""
So, "Lucas Andrade \"My name\""
should result in what you're looking for, an escaped and an escaped
"
I am not very fluent in Ruby, but this is commonly done with "\"
, resulting in ""
So, "Lucas Andrade \"My name\""
should result in what you're looking for, an escaped and an escaped
"
edited Nov 21 '18 at 8:17
Stefan
75.6k894142
75.6k894142
answered Nov 20 '18 at 20:07
David HDavid H
461
461
add a comment |
add a comment |
When you need to send the string as JSON to an API, why don't you use JSON.generate
to escape the string as needed?
JSON.generate("Lucas Andrade "My name"")
1
The OP should probably generate the whole JSON structure out of a Ruby hash.
– Stefan
Nov 21 '18 at 8:10
add a comment |
When you need to send the string as JSON to an API, why don't you use JSON.generate
to escape the string as needed?
JSON.generate("Lucas Andrade "My name"")
1
The OP should probably generate the whole JSON structure out of a Ruby hash.
– Stefan
Nov 21 '18 at 8:10
add a comment |
When you need to send the string as JSON to an API, why don't you use JSON.generate
to escape the string as needed?
JSON.generate("Lucas Andrade "My name"")
When you need to send the string as JSON to an API, why don't you use JSON.generate
to escape the string as needed?
JSON.generate("Lucas Andrade "My name"")
answered Nov 20 '18 at 20:23


spickermannspickermann
59.3k65676
59.3k65676
1
The OP should probably generate the whole JSON structure out of a Ruby hash.
– Stefan
Nov 21 '18 at 8:10
add a comment |
1
The OP should probably generate the whole JSON structure out of a Ruby hash.
– Stefan
Nov 21 '18 at 8:10
1
1
The OP should probably generate the whole JSON structure out of a Ruby hash.
– Stefan
Nov 21 '18 at 8:10
The OP should probably generate the whole JSON structure out of a Ruby hash.
– Stefan
Nov 21 '18 at 8:10
add a comment |
You can wrap it in single quote marks.
str = 'Lucas Andrade "My name"'
=> "Lucas Andrade "My name""
This does not answer the question. He needs the output to include the backslash character and the output ofputs 'Lucas Andrade "My name"'
does not include a backslash.
– anothermh
Nov 20 '18 at 20:27
There's a bit of confusion from OP: ` So when I print my str I should see this: "Lucas Andrade "My name""` which my answer does. But OP also says they want the backslash therein.
– well-i-better-get-rolling
Nov 20 '18 at 20:28
In rubyputs
andprint
are different, that's why I saidprint
. In your answer the are just represented by ruby output syntax, the are not part of the string.
– Lucas Andrade
Nov 20 '18 at 20:58
You're right. You did sayprint
.
– well-i-better-get-rolling
Nov 20 '18 at 21:13
puts
is likeprint
with newline (if missing).
– Stefan
Nov 21 '18 at 7:54
add a comment |
You can wrap it in single quote marks.
str = 'Lucas Andrade "My name"'
=> "Lucas Andrade "My name""
This does not answer the question. He needs the output to include the backslash character and the output ofputs 'Lucas Andrade "My name"'
does not include a backslash.
– anothermh
Nov 20 '18 at 20:27
There's a bit of confusion from OP: ` So when I print my str I should see this: "Lucas Andrade "My name""` which my answer does. But OP also says they want the backslash therein.
– well-i-better-get-rolling
Nov 20 '18 at 20:28
In rubyputs
andprint
are different, that's why I saidprint
. In your answer the are just represented by ruby output syntax, the are not part of the string.
– Lucas Andrade
Nov 20 '18 at 20:58
You're right. You did sayprint
.
– well-i-better-get-rolling
Nov 20 '18 at 21:13
puts
is likeprint
with newline (if missing).
– Stefan
Nov 21 '18 at 7:54
add a comment |
You can wrap it in single quote marks.
str = 'Lucas Andrade "My name"'
=> "Lucas Andrade "My name""
You can wrap it in single quote marks.
str = 'Lucas Andrade "My name"'
=> "Lucas Andrade "My name""
answered Nov 20 '18 at 20:10


well-i-better-get-rollingwell-i-better-get-rolling
3,46132860
3,46132860
This does not answer the question. He needs the output to include the backslash character and the output ofputs 'Lucas Andrade "My name"'
does not include a backslash.
– anothermh
Nov 20 '18 at 20:27
There's a bit of confusion from OP: ` So when I print my str I should see this: "Lucas Andrade "My name""` which my answer does. But OP also says they want the backslash therein.
– well-i-better-get-rolling
Nov 20 '18 at 20:28
In rubyputs
andprint
are different, that's why I saidprint
. In your answer the are just represented by ruby output syntax, the are not part of the string.
– Lucas Andrade
Nov 20 '18 at 20:58
You're right. You did sayprint
.
– well-i-better-get-rolling
Nov 20 '18 at 21:13
puts
is likeprint
with newline (if missing).
– Stefan
Nov 21 '18 at 7:54
add a comment |
This does not answer the question. He needs the output to include the backslash character and the output ofputs 'Lucas Andrade "My name"'
does not include a backslash.
– anothermh
Nov 20 '18 at 20:27
There's a bit of confusion from OP: ` So when I print my str I should see this: "Lucas Andrade "My name""` which my answer does. But OP also says they want the backslash therein.
– well-i-better-get-rolling
Nov 20 '18 at 20:28
In rubyputs
andprint
are different, that's why I saidprint
. In your answer the are just represented by ruby output syntax, the are not part of the string.
– Lucas Andrade
Nov 20 '18 at 20:58
You're right. You did sayprint
.
– well-i-better-get-rolling
Nov 20 '18 at 21:13
puts
is likeprint
with newline (if missing).
– Stefan
Nov 21 '18 at 7:54
This does not answer the question. He needs the output to include the backslash character and the output of
puts 'Lucas Andrade "My name"'
does not include a backslash.– anothermh
Nov 20 '18 at 20:27
This does not answer the question. He needs the output to include the backslash character and the output of
puts 'Lucas Andrade "My name"'
does not include a backslash.– anothermh
Nov 20 '18 at 20:27
There's a bit of confusion from OP: ` So when I print my str I should see this: "Lucas Andrade "My name""` which my answer does. But OP also says they want the backslash therein.
– well-i-better-get-rolling
Nov 20 '18 at 20:28
There's a bit of confusion from OP: ` So when I print my str I should see this: "Lucas Andrade "My name""` which my answer does. But OP also says they want the backslash therein.
– well-i-better-get-rolling
Nov 20 '18 at 20:28
In ruby
puts
and print
are different, that's why I said print
. In your answer the are just represented by ruby output syntax, the are not part of the string.– Lucas Andrade
Nov 20 '18 at 20:58
In ruby
puts
and print
are different, that's why I said print
. In your answer the are just represented by ruby output syntax, the are not part of the string.– Lucas Andrade
Nov 20 '18 at 20:58
You're right. You did say
print
.– well-i-better-get-rolling
Nov 20 '18 at 21:13
You're right. You did say
print
.– well-i-better-get-rolling
Nov 20 '18 at 21:13
puts
is like print
with newline (if missing).– Stefan
Nov 21 '18 at 7:54
puts
is like print
with newline (if missing).– Stefan
Nov 21 '18 at 7:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400700%2finside-a-string-does-not-escape-anything%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"
inside a string does not escape anything" – not true, it escapes the
"
which would otherwise end the string.– Stefan
Nov 21 '18 at 8:12