Insert space or enter in sqlite in ios sdk - ios

I want to insert space or enter in sqlite database.
Is their any way to insert the space or enter.
Can we do it by ascii character.
We can do it by using nsattributed string and but can we do it by nsstring?

Yes, simply use \t (space - tab) or \n (enter - new line) with NSString.
e.g. NSString *test = [NSString stringWithFormat:#"This is an example\nTo show you the great things\t:D"]; and you can save it into your db, when you show it in a UILabel or UITextView \n and \twill convert to new line or tab space.
Update: even you can use html tags for this, use (space) and <br> for new line. Or some other tags, <pre> to show preformated text.
I'm not sure whether sqlite deny escape characters for space and new line, in case you can replay them with html tags.

I had solved this issue by below code:-
- (BOOL)textView:(CustomTextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
str_Notes=[str_Notes stringByAppendingString:text]; //Where str_Notes is NSstring
return YES;
}
And then i use string in my insert query. and i is working perfectly fine.

Related

How to make this UILabel move the email address to the next Line?

I have a simple UILabel that is printing text as follows:
John Doe sent a message to blahblah-
blah#blahblah.com
Thus, the email address here : blahblah-blah#blahblah.com is being cut and partially displayed on the next line. What do I need to do to make it display as :
John Doe sent a message to
blahblah-blah#blahblah.com
?
I already have the following :
self.mailLabel.lineBreakMode = NSLineBreakModeByWordWrapping;
self.mailLabel.numberOfLines = 0;
The string in question is :
[NSString stringWithFormat:#"You sent a message to %#", emailAddress];
What should I do here? Remember, the name can be long and hence, adding a line break in the string won't work because I don't want the following case :
Jonathon Dawson sent a message
to
blahblah-blah#blahblah.com
which should be
Jonathon Dawson sent a message
to blahblah-blah#blahblah.com
self.mailLabel = [NSString StringWithFormat:#"You sent a message to\n%#"];
You use \n to make a new line.
Also, make sure you set the numberOfLines to 2 on the label.
You need to add ZWNBSP(Zero-width no-break space) characters to the left and to the right of - (hyphen, aka dash) symbol:
self.mailLabel.text = [self.mailLabel.text stringByReplacingOccurrencesOfString:#"-" withString:#"\u2060-\u2060"];
Remarks:
U+2060 - Zero-width no-break space Unicode character prevents any line breaks that may be inserter to wrap the word before and after it. As soon as UILabel (as well as other text controls in Cocoa) respects Unicode, you will get text without undesired line breaks.
Wikipedia link: http://en.wikipedia.org/wiki/Zero-width_no-break_space

Convert Unicode Emoji to NSString (Not \ue415 format)

I am trying to convert an emoji to an NSString. I previously asked a question on how to do the opposite (convert an NSString to a unicode) at NSString to Emoji Unicode. I thought perhaps it would be best to ask this as a new question here.
How can I convert an NSString containing an emoji (😃) to an NSString containing a unicode in this format (U0001F603)?
This question is basically the reverse engineering of the solution from the previous page. The catch is the project does not use the \ue415 format, but rather the U0001F603 format.
Edited per comment:
2014-07-11 11:37:19.448 emoticon[******] unicode: 😂
unicode = [NSString stringWithFormat:#"%#\\UFE0E", unicode];
2014-07-11 11:37:19.449 emoticon[******] unicode: 😂\UFE0E
SECOND COMMENT RESPONSE
I'm not entirely sure if I follow what you mean by I didn't add the first line of code. I hope I haven't been unclear. To try and be more specific on what I would like, I logged your code in, and then logged what I wish to get:
NSString *first = #"😃";
NSString *second = #"😃\\UFE0E";
NSString *third = #"U0001F603\\UFE0E";
2014-07-11 12:00:45.815 emoticon[******] first: 😃, second: 😃\UFE0E, third: U0001F603\UFE0E
2014-07-11 12:00:45.816 emoticon[******] desiredString: U0001F603
My hope is to produce the desiredString by converting the emoji to the desired string.
THIRD COMMENT RESPONSE
What you need is using the escape character \U0000FE0E to the end of all Unicode characters to make it skip the emoji and display the proper Unicode character.
Here's the code:
#"😃" //This shows the colorful emoji icon.
#"😃\U0000FE0E" //This shows the good old Unicode character.
You can also add it to the character code:
#"U0001F603\U0000FE0E"
Here is a "pseudo-code" (JavaScript, you can run it in your browser's console) ..for opposite-direction.
String.fromCharCode(
((0x1F603 - 0x10000) >> 10) | 0xD800
,
((0x1F603 - 0x10000) % 0x400) | 0xDC00
)
=>>"😃"
Just reverse the bytewise operations, and zero-pad it.
If you are a programmer it should be more than easy for you.
..give a man a fish...
source: JavaScript Ninja - Easy Unicode Emoji Generator 😁🌠🐬

Excessive inter-word spacing when parsing XML

I am parsing XML using NSXMLParser. Everything works good except one XML tag:
<place>USA , Boston</place>
when I parse this tag, the value is
USA , Boston
Somehow spaces are added between words. Any ideas why it is happening and how can I fix it?
UPDATED
The code I am using is straightforward. The string that I receive in parser:foundCharacters: delegate call is already with spaces. I am using:
[_currentString appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
to remove spaces and new lines, but it is only for the beginning and the end of the string.
In FoundCharacters method we have to replace these special character.
string =[string stringByReplacingOccurrencesOfString:#"\t"
withString:#""];
[_currentString appendString:string];
Will be good if you show you code of in short if you can edit the XML format than one solution will be you can add the tag value between CDATA like
<place><![CDATA[USA , Boston]]></place>
CDATA section is a section of element content that is marked for the parser to interpret as only character data

iOS, sqlite3 & unicode char

For my app I want to be able to use unicode caracters like \n, and these ones :
http://www.easyapns.com/category/just-for-fun
The text is stored in a sqlite3 database, and when I read it, I get for example the text \ue415 instead of the smiley. I neither have a line break, but a \n .
I'm able to display the smileys and line breaks using this piece of code :
NSString* unicodeString = [myString stringByReplacingOccurrencesOfString:#"\\n" withString:#"\n"];
unicodeString = [unicodeString stringByReplacingOccurrencesOfString:#"\\ue022" withString:#"\ue022"];
// etc...
But I would like to find a generic way to do this, in order to be able to display all the unicode caracters.
I'm getting the text from my sqlite3 database this way :
NSString* title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
I tried to replace \\ by \, but it is not possible to write the string #"\", because it escapes the " ... I tried to replace \\\\ by \\, but it doesn't work. I also tried to get the string from the database using other encoding, without success...
Any idea ?
I finally found my solution there (not the accepted answer, the one from Nikolai Ruhe) :
Using Objective C/Cocoa to unescape unicode characters, ie \u1234
NSString* convertedString = [myString mutableCopy];
CFStringRef transform = CFSTR("Any-Hex/Java");
CFStringTransform((__bridge CFMutableStringRef)convertedString, NULL, transform, YES);
It does not escape the \n though, but it can easilly be done with stringByReplacingOccurrencesOfString.

Showing unicode in the console in the right format

NSSet *subFolders = [_account subscribedFolders];
NSLog(#"subFolders: %#",subFolders);
Output:
...
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea",
"[Gmail]/\U05d7\U05e9\U05d5\U05d1"
...
Is there any way I can show the above text in its original language (Hebrew) ?
Things I tried:
changing the debugger from LLDB to GDB - Didn't work
Checking under preferences -> Text Editing UTF-* is selected
Thanks
There is no issue with displaying unicode characters in the console, so I would assume it's the way the string is getting into the set in the first place.
I would suggest iterating over all the objects inside subFolders with something like:
for( id object in [subFolders allObjects] ) {
//Print out the name of the item explicitly
}
Even if this doesn't work, it at least lets you work with the strings directly. If it's still printing out:
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea"
It would look as if you're being sent escaped unicode characters, and I would suggest this: https://stackoverflow.com/a/7861345/352891 - this may work directly on NSSet's description
NSString* strOld=[NSString stringWithFormat:#"%#",responseObject];
NSLog(#"%#",[NSString
stringWithCString:[strOld cStringUsingEncoding:NSUTF8StringEncoding]
encoding:NSNonLossyASCIIStringEncoding]);

Resources