How to add quotes to string in Swift?
I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :
let quotedString = String(format:"This is my "%@" in statement",QuotedString)
But this creates :
"This is my "QuotedString" in statement".
swift string
add a comment |
I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :
let quotedString = String(format:"This is my "%@" in statement",QuotedString)
But this creates :
"This is my "QuotedString" in statement".
swift string
3
Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into aUILabel
, aUITextView
, etc. and the backslash shouldn't appear.
– Larme
Dec 29 '18 at 16:22
add a comment |
I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :
let quotedString = String(format:"This is my "%@" in statement",QuotedString)
But this creates :
"This is my "QuotedString" in statement".
swift string
I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :
let quotedString = String(format:"This is my "%@" in statement",QuotedString)
But this creates :
"This is my "QuotedString" in statement".
swift string
swift string
edited Dec 29 '18 at 17:00
rmaddy
240k27315379
240k27315379
asked Dec 29 '18 at 16:17
ShirishShirish
709
709
3
Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into aUILabel
, aUITextView
, etc. and the backslash shouldn't appear.
– Larme
Dec 29 '18 at 16:22
add a comment |
3
Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into aUILabel
, aUITextView
, etc. and the backslash shouldn't appear.
– Larme
Dec 29 '18 at 16:22
3
3
Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a
UILabel
, a UITextView
, etc. and the backslash shouldn't appear.– Larme
Dec 29 '18 at 16:22
Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a
UILabel
, a UITextView
, etc. and the backslash shouldn't appear.– Larme
Dec 29 '18 at 16:22
add a comment |
2 Answers
2
active
oldest
votes
No, it doesn’t create "This is my "QuotedString" in statement"
, with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).
But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count
of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.
Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .
– Shirish
Dec 30 '18 at 8:21
add a comment |
are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see
in string. Try to print string on console and see the output.
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%2f53971215%2fhow-to-add-quotes-to-string-in-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
No, it doesn’t create "This is my "QuotedString" in statement"
, with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).
But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count
of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.
Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .
– Shirish
Dec 30 '18 at 8:21
add a comment |
No, it doesn’t create "This is my "QuotedString" in statement"
, with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).
But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count
of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.
Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .
– Shirish
Dec 30 '18 at 8:21
add a comment |
No, it doesn’t create "This is my "QuotedString" in statement"
, with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).
But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count
of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.
No, it doesn’t create "This is my "QuotedString" in statement"
, with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).
But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count
of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.
edited Dec 29 '18 at 16:36
answered Dec 29 '18 at 16:26
RobRob
298k49556724
298k49556724
Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .
– Shirish
Dec 30 '18 at 8:21
add a comment |
Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .
– Shirish
Dec 30 '18 at 8:21
Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .
– Shirish
Dec 30 '18 at 8:21
Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .
– Shirish
Dec 30 '18 at 8:21
add a comment |
are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see
in string. Try to print string on console and see the output.
add a comment |
are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see
in string. Try to print string on console and see the output.
add a comment |
are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see
in string. Try to print string on console and see the output.
are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see
in string. Try to print string on console and see the output.
answered Dec 29 '18 at 17:17
Vikas KeskarVikas Keskar
513
513
add a comment |
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%2f53971215%2fhow-to-add-quotes-to-string-in-swift%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
3
Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a
UILabel
, aUITextView
, etc. and the backslash shouldn't appear.– Larme
Dec 29 '18 at 16:22