NSLocalizedString with superscript [duplicate] - ios

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.

Related

IOS NSCharacterSet for emoji and latin characters

I'm trying to limit text user input to latin/english characters and emojis.
Is it possible to create an NSCharacterSet that includes all of these characters?
I tried using a keyboard type ASCIICapable on my input views, but then I don't get emoji input.
There's nothing built in to create such a specific character set. You'll have to do it yourself by character range.
The Emoji characters are essentially in the range \U1F300 - \U1F6FF. I suppose a few others are scattered about.
Use an NSMutableCharacterSet to build up what you need.
NSMutableCharacterSet *aCharacterSet = [[NSMutableCharacterSet alloc] init];
[aCharacterSet addCharactersInRange:NSMakeRange(0x1F300, 0x1F700 - 0x1F300)]; // Add most of the Emoji characters
[aCharacterSet addCharactersInRange:NSMakeRange('A', 'Z'-'A'+1)]; // Add uppercase
[aCharacterSet addCharactersInRange:NSMakeRange('a', 'z'-'a'+1)]; // Add lowercase
Swift equivalent of rmaddy's answer to add up ranges in a CharacterSet:
var aCharacterSet = CharacterSet()
aCharacterSet.insert(charactersIn: "\u{1F300}"..<"\u{1F700}") // Add most of the Emoji characters
aCharacterSet.insert(charactersIn: "A"..."Z") // Add uppercase
aCharacterSet.insert(charactersIn: "a"..."z") // Add lowercase
Also, you will find the complete list of Unicode ranges for emoji on http://www.unicode.org/charts/ under Emoji & Pictographs.

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 +

iOS - How can I put special characters (music notation) in a UILabel?

I would like to create a label with some unicode text and a music note. The notes are shown below:
I have tried:
titleLabel.text = #" title + ♫";
but that results in:
I must be doing something dumb.. Any advice welcome.
The number column in your table actually contains HTML/SGML/XML entities with decimal values. A unicode escape sequence in NSString takes the hexadecimal value, so your note ♫ would be the hex value 0x266b to be used like this
titleLabel.text = #" title \u266b";
Hit cmd+cntrl+space in Xcode, and search for 'note'. There are some u may use. Just double click one and it will be written where your cursor is in the code.

Unichar with specific characters [duplicate]

This question already has answers here:
Objective c doesn't like my unichars?
(3 answers)
Closed 9 years ago.
I'm trying to add some specific characters to my
unichar rusLetter [] = { 'Ж', 'Й', }
I want actually to add all letters from russian alphabet. Using above line of code, i get an error:
Character too large for enclosing character literal type
Any ideas how to fix that? And maybe there is an easier way to add all letters, not to type all of them.
Thanks
the ' literal (single quote) means a char and that is too small to hold the symbols.
In ObjC use an NSString to hold it
NSString *rusLetters = #"ЖЙ";
unichar c1 = [rusLetters characterAtIndex:0];
unichar c2 = [rusLetters characterAtIndex:1];

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