add quotation marks ( " ) in an array in Swift [duplicate] - ios

This question already has answers here:
Is it possible to include a quotation mark as part of an nsstring?
(7 answers)
Closed 7 years ago.
I am creating custom keyboard and for that I want to add quotation marks in an array for setting it as an button title. So how can I do these in Swift?
Here is a below code I tried:
symbolArray = ["+","-"," " "]

You have to escape the quotes with a backslash. "\""

Related

Capitalize First Letter of each word in a string (Swift) [duplicate]

This question already has answers here:
How to capitalize each word in a string using Swift iOS
(8 answers)
Closed 5 years ago.
I want output like this:
var String1 = "stack over flow"
var desiredOutPut = "Stack Over Flow"
Also, I want this output in TextField event named "textFieldDidChange" so it must be efficient as well.
var desiredOutPut = String1.capitalized

How do you confirm a string only contains numbers in Swift? [duplicate]

This question already has answers here:
Finding out whether a string is numeric or not
(18 answers)
Closed 7 years ago.
How can I check, if searchView contains just numbers?
I found this:
if newText.isMatchedByRegex("^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$") { ... }
but it checks if text contains any number. How can I do, that if all text contains just numbers in Swift?
Here is the solution you can get all digits from String.
Swift 3.0 :
let testString = "asdfsdsds12345gdssdsasdf"
let phone = testString.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")
print(phone)
you can use "^[0-9]+$" instade "^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$"
This will accept one or more digits, if you want to accept only one digit then remove +

NSLocalizedString with superscript [duplicate]

This question already has an answer here:
Unicode not converted when displayed
(1 answer)
Closed 9 years ago.
How would you add superscript inside an NSLocalized string?
I'm trying to write a superscript 2, if I do it like this, it works:
[title setText:[NSString stringWithFormat:#"CO\u00B2 %#",NSLocalizedString(#"c04View01_title", #"Title for current page")]];
But if I add the superscript to the localized string, it doesn't work, it just interprets that as 5 characters:
"c04View01_title" = "CO\u00B2 PROGRAMMERS";
[title setText:NSLocalizedString(#"c04View01_title", #"Title for current page")]];
The problem happens, when the string with the superscript is between strings, so I need to split the string in two parts, but in some languages the superscripted string ends up at the end of the sentence.
Try using an upper-case 'U' for the backslash-escape, as per Apple's documentation:
"c04View01_title" = "CO\U00B2 PROGRAMMERS";
You can also just put the character directly in the strings file, un-escaped. There is no need to backslash-encode most characters.

Erlang Tuple to String [duplicate]

This question already has answers here:
Convert erlang terms to string, or decode erlang binary
(2 answers)
Closed 9 years ago.
Is there a way how to convert a tuple to a string ?
Consider I have the following list :
[{atom,5,program},{atom,5,receiving},{nil,5}]
I wish to convert this into the following string:
"{atom,5,program},{atom,5,receiving},{nil,5}"
I have tried using erlang:tuple_to_list on each element in the list, which returns
A = [atom,5,program]
Eventually, I can't concatenate that with "{" ++ A ++ "}"
Any ideas how I can turn that to a string ?
Term = [{atom,5,program},{atom,5,receiving},{nil,5}].
lists:flatten(io_lib:format("~p", [Term])).

Alternatives to #""? [duplicate]

This question already has answers here:
How to escape double quotes in string?
(3 answers)
Closed 10 years ago.
I have a string that has multiple " in it, which is written inside of #"" and of course, xcode sees this as me ending the #". Is there any alternatives I can use for #"" that would do the same thing?
It's done with escape chars. #"My name is \"Someone\". Blabla.";

Resources