I trying to make an app where the user enters a text then save it to the database but before that it will be added to NSMutableArray. The thing is when I log the array, it removes the encoding and shows the text like this:
\U0662\U0664.\U0660\U0665.\U0662\U0660\U0661\U0664 \U0660\U0662:\U0663\U0662 \U0635
Can someone help me and tell me how to re-encode the text to arabic?
EDIT : the text is not showing correctly neither in the log or the interface.
Logging the array and logging the string is not the same thing and the string will display differently in the console depending on how you do it. That is, there is a difference between logging:
po yourArray
and
po [yourArray firstObject]
As long as the string displays correctly in your interface both before and after storing it in the database you should have nothing to worry about. The way the string is printed to the console when you log the contents of the array does not affect how it appears when you display it using a label in your UI.
Related
I'm working on a GUI using PyQt5 and a QTableWidget containing CheckBoxes items. I populate the table with data from json file and the user can check/uncheck items.
When I want to retrieve data from my QTableWidget items, I get unexpected error due to some characters : \x19. The character in question is ’ which is well displayed elsewhere.
I don't understand the issue as my input json data is utf-8, I use python3 and when I check my data, I see no encoding issue. This error occurs only when calling text() method on QTableWidgetItem.
As I don't see any other way to retrieve data from my items, I'm quite stuck on it.
with open(filepath) as file:
self.data = json.load(file)
for key, value in self.data.items():
print(key, self.data[key])
keyword_box = QTableWidgetItem(key)
I get no error if I use key to compare with other string for example but when I want to retrieve data (no editing was performed by the user, strings didn't change)
items = self.table.selectedItems()
for item in items:
print(item.text())
I get unknown character in my console and if I try to use the value, I get a \x19 character which fails when I use it to compare with keys in my dictionary.
Could this come from a bug in QTableWidgetItem text() method ?
In my app Web services are created in dot net and i am consuming those and I am getting response.In that all the fields like company,type,location everything are strings and there is no problem with this..And there is one more field called Exhibit number actually it is a Integer but they are created as string only.While I am displaying this it is showing zero instead of that number.. Here is my code...
//Storing into Array
[SurveyFilesArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:[dic objectForKey:#"FileName"],#"FileName",[dic objectForKey:#"ExibhitNumber"],#"ExhibitNumber",[dic objectForKey:#"Description"],#"Description",[dic objectForKey:#"FileQuality"],#"FileQuality",nil]];
//Retrieving from Array..
NSLog(#"???%#???",[NSString stringWithFormat:#"%d",[[[SurveyFilesArray objectAtIndex:indexPath.row]objectForKey:#"ExibhitNumber"]intValue]]);
NSLog(#"%d",[[[SurveyFilesArray objectAtIndex:indexPath.row]objectForKey:#"ExibhitNumber"]intValue]);
You have typos in your code.
In the order of your code:
Ex-ib-hit-Number
Ex-hib-it-Number
These are 2 different strings.
In your example code you save it correctly written as Ex-hib-it. But you try to access it with ex-ib-hit afterwards. This cannot work.
I have a series of textfields the user will enter in values (one is a string the others numeric). When I try to get the text from:
NSString *strCal = txtfieldCal.text;
NSLog(#"cal entered: %a", strCal);
Returns:
calories Entered: -0x1.fd55804e2e26p+0
I have the outlets referenced correctly in IB.
I don't know if this matters or not, but I can populate the textfields on viewload, but I cannot get the value afterwards.
You need to use %# to put strings into NSLog. %a likely shows something else, - it looks like a number from the man page in terminal (type man printf)
NSLog(#"cal entered: %#", strCal);
Just thought that you may well WANT a number. Well you get a string -its a text field. To get a number, you call something like
NSLog(#"cal entered: %f", [strCal doubleValue]);
I have a Form with a textarea. When the Form is send off, the Datamapper enters the Data into the Database.
My Question now, how to I keep all the Line breaks to be saved in the Database?
In my view I use
$this->escape($entry->description)'
I think escape() will filter this out won't it?
So I tried using the below
echo nl2br($entry->description)
I have copied some text with line breaks directly into the database, since I don't know how it is supposed to be saved, but nothing changed.
How do I save it in the Database? I just use $table->insert($data);
How do I than display the text with the line-breaks in my view?
I hope someone can help, because I can not find a solution. Thank you very much.
The following worked fine for me with no problems:
$db = Zend_Db_Table::getDefaultAdapter();
$db->insert('testing', array('description' => "This is a test\nwith multiple\nlines in the db\n\nmore stuff"));
$select = $db->select()->from('testing');
$results = $select->query();
$row = $results->fetch();
$this->view->description = $row['description'];
// in the view:
echo nl2br($this->description);
In the view I had my string printed out with multiple line breaks still in place.
The escape only calls htmlspecialchars() by default, which wouldn't effect the newlines. But you will need to call nl2br because newlines won't cause the string to span multiple lines in the webpage, that is why you use nl2br.
So even when you manually inserted data with line breaks into the DB, you cannot get the line breaks when you select the data from the table?
I have some XML which looks like this:
<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><array><data>
<value><array><data>
<value><dateTime.iso8601>20100508T14:49:56</dateTime.iso8601></value>
<value><string></string></value>
<value><string>comment</string></value>
<value><string></string></value>
<value><string>Milestone milestone1 deleted</string></value>
<value><int>1</int></value>
</data></array></value>
</data></array></value>
</param>
</params>
</methodRepsonse>
NSXMLParser seems to not be giving any data back for the blank values resulting in an array with 4 items in it instead of 6.
Is there anything I can do to NSXMLParser to make it return an empty string for the blank values so that I can maintain the order of the data when it is returned?
So after whipping up a quick sample with a delegate that just prints out what's happening during parsing I don't see anything at all wrong with what's being parsed.
I suspect however that you're relying on an incorrect expectation that between calls to didStartElement... and didEndElement... you should get a foundCharacters... call with an empty string? My question is based on the way you phrased the title of your question because there's no such thing as a "blank value." Either there is a value, or there isn't.
Imagine instead your XML contained <string/> instead of the exactly equivalent <string></string>. You still get start/end notifications.
You should be creating your NSMutableString (presumably the type that you're using for your <string> elements) in didStartElement... when <string> is found, appending to that string IF foundCharacters... is called (it can get called more than once with the value in chunks), and tossing it into your array when it's done on didEndElement....
If you really want to be more robust, you'll also be wanting detect an error condition if you find the start of a new element before your string ends, assuming that it is in fact an error for you.
Not quite sure I understand your problem here. NSXMLParser would at least report the beginning and end of the elements. Would that not be enough the get them in the right order?