Formatting NSString for superscript and subscript - ios

I am writing a utility app for some coworkers. The app is essentially a custom notepad, with buttons that represent the shorthand they use to transcribe a task. All of the buttons add a string to arrays that I have set up to hold the transcript, and I add the strings to the row arrays like this.
[currentRow addObject:#"("];
Some of the shorthand needs to be written in subscript, and some in superscript. There are not Unicode characters for all of the characters that I need, so I have been trying to sort through the code around Attributed Strings,but I'm not quite getting it. Does anyone have advice on this or some sample code?
Also, after this transcript is printed to the screen during transcription, I send it to an email message body.. so I assume I'll need to worry about formatting there as well. I am currently using plain text, but the email could be HTML. Thanks!

If you display the text in a WebView you can use html tags to set superscript. It also has the advantage to run on older iOS versions and you can reuse the text in your mail.
NSString *myText=#"This text contains <sub>subscript</sub> and <sup>superscript</sup> text.";
[self.myWebView loadHTMLString:myText baseURL:nil];

Related

Escaping or replacing curly/smart quotes in Twitter widget: Tweet text intent

I'm using selected/highlighted text by the user to generate the intent/tweet?text= content for the Twitter widget's "Tweet text" function.
It works great except when it encounters either opening or closing double/single curly quotes within the element's content: ‘ ’ “ ” (‘ ’ “ ”). When any of those characters is included in the selected text, the entire Tweet text dialog window is blank.
I've tried various javascript methods to search/replace the ASCII codes or the Unicode versions of those but to no avail.
The escape(text) method is already being used before the text gets to the Twitter widget, so I'm confused as to why it's choking. In the location bar it shows that these characters are being converted to their Unicode versions like u201C.
What could be causing the Tweet text box to fail on these characters even though it seems to be properly converting them anyway?
I discovered that one needs to search/replace the literal entities themselves, not ASCII codes nor their Unicode counterparts.
So the solution for using selected text in a Twitter widget text intent is:
text = text.replace(/“/g, "\'").replace(/”/g, "\'").replace(/‘/g, "\'").replace(/’/g, "\'");
The entities don't need to be escaped.

How to Insert NSAttributedString using custom keyboard extension?

I want to write text in some custom fonts using keyboard Extension as these apps (1,2,3,4) are doing. I know how we can insert normal string in document proxy.
[self.textDocumentProxy insertText:mystring];
I have tried to insert NSAttributedString using above approach but I can't see any way to insert NSAttributedString to document proxy.
Some one can guide what will the best way to get rid of this issue? any suggestion will be appreciated.
It is not possible to insert attributed strings (or otherwise rich content) using the text document proxy.
The keyboards you have linked are not using custom fonts. They use (or abuse) Unicode symbols such as Enclosed Alphanumerics and Enclosed Alphanumeric Supplement.
In other instances, different alphabet symbols with visual similarity to latin symbols are used to create "funky" text, like here.
Last, some keyboard extensions, like the image keyboards, use the pasteboard to copy the rich content, and the user is responsible to paste it where he seems fit.
The apps you are referring to don't use NSAttributedString or custom fonts. They simply replace letters with similar-looking Unicode characters. You can see these characters in any OS X app inside Edit -> Special Characters menu.

RTF file to TXT/CSV file in objective-c?

I have RTF files containing that sort of content:
long_text_description_1 number1a number1b number1c
long_text_description_2 number2a number2b number2c
long_text_description_3 number3c
long_text_description_4 number4a number4b number4c
…
I need to extract the plain raw text without the colours, fonts and other formatting thing.
The only thing I need to keep are the most basic row/column information, ideally I would like a CSV file.
The file I get contain all the formatting:
{\cs18\lang1033\langfe1033\f0\b\i0\ul0\strike0\scaps0\fs15\afs15\charscalex100\expndtw0\cf1\dn0 number1a}
What is the best way to remove all rtf information while only keeping the row information?
Trying to figure out myself many many regular expressions sound dangerous unless there is a complete understanding of the RTF format.
What I could find on the Internet mostly focused on using Windows languages & libraries unavailable in iOS.
All rtf tags are in the form \xxx.
Try using a regular expression like "\\S+" and remove all matches or replace with nothing.
For your example, you'll end up with { number1a} This will remove any backslash followed by any characters.

Escape bad characters for iOS UILabel?

I'm feeding some NSString data (forum posts queried from my website) into a UILabel as part of my first app. Thing is, sometimes, depending on the content of the post, the Label goes entirely blank. I've tinkered enough to discern that there are certain characters that cause the problem, but I can't quite pin down the full set.
Is there a collected list of character types to watch out for with this kind of thing? And even better, is there a method for escaping them, or automatically converting them into something more acceptable?
Thank you for helping out a n00b!
Looks like you have whitespace or new line in your string:
Try this:
NSString* labelText = [stringFromWebsite stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]
I am trying to give you some clue even you haven't put piece of code here in your question.
You should firstly try to encode that coming String by using appropriate method like encoding:NSUTF8StringEncoding and still and try to set decoded string to your UIlabel.
Another alternative is that you can create some regex for filtering purpose of that coming string. you can find many of similar thread over the google.

Grails: User inputs formatted string, but formatting not preserved

I am just starting a very basic program in Grails (never used it before, but it seems to be very useful).
What I have so far is:
in X.groovy,
a String named parameters, with constraint of maximum length 50000 and a couple other strings and dates, etc.
in XController.groovy,
static scaffold = X;
It displays the scaffold UI (very handy!), and I can add parameter strings and the other objects associated with it.
My problem is that the parameters string is a long string with formatting that is pasted in by the user. When it is displayed on the browser, however, it does not retain any carriage returns.
What is the best way to go about this? I'm a very beginner at Grails and still have lots and lots of learning to do on this account. Thanks.
The problem is that the string is being displayed using HTML which doesn't parse \n into a new line by default. You need to wrap the text in <pre> (see: http://www.w3schools.com/tags/tag_pre.asp) or replace the \n with <br/> tags to display it correctly to the user.

Resources