Dear All,
I have a strange (stupid) problem when trying to read "Arabic text" from a given file. Let us assume that I have a text file called TEXT.txt which is encoded UTF-8 and looks like this (Arabic text is from RightToLeft):
:xxx xxxx xx xxx
.xxx, xxxxxxx xxxxx xxx
When I am trying to read TEXT.txt in Xcode by using
UITextView *about;
about.textAlignment = UITextAlignmentRight;
NSString *textFilePath = [[NSBundle mainBundle] pathForResource:#"TEXT" ofType:#"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:nil];
about.text = fileContents;
NSLog(#"The text is: \n %#",about.text);
Which is I believe is the right way!!! Then it shows on iPhone Simulator and on the device as this:
xxx xxxx xx xxx:
xxx, xxxxxxx xxxxx xxx.
Which is not the right text to be shown !!!!!!!!!!!!!! What the heck is the problem of the ":" colon and the "." period going on the wrong side. I had a headache of this problem as I have been trying to solve for a long time already. So please Help!!!
Best Regards;
I don't think there is a way to automatically force right to left layout. However, you can make a method that will reverse your text. This will read each character and putting it into a mutable string. A quick search came up with this:
-(NSString *) reverseString
{
NSMutableString *reversedStr;
int len = [self length];
// Auto released string
reversedStr = [NSMutableString stringWithCapacity:len];
// Probably woefully inefficient...
while (len > 0)
[reversedStr appendString:
[NSString stringWithFormat:#"%C", [self characterAtIndex:--len]]];
return reversedStr;
}
Related
I am trying to access a core data model stored in another view controller. Currently, I have a few strings that i combine into one and save to the clipboard. But, when I paste the text, it shows NULL on the places where the three imported core data entries are supposed to be. What have I done wrong? Here is some code:
NSString *namevalue;
NSString *versionvalue;
NSString *companyvalue;
namevalue = [self.device valueForKey:#"name"];
versionvalue = [self.device valueForKey:#"version"];
companyvalue = [self.device valueForKey:#"company"];
NSString *shareString = [NSString stringWithFormat:#"I have performed %# minutes of %# %#",namevalue, versionvalue, companyvalue];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:shareString];
I'm trying to write some double values to a text file the user creates via a SaveFileDialog, but everytime I do a streamWriterVariable->Write(someDoubleVariable), I instead see some kind of weird ASCII character in the text file where the double should be (music note, |, copyright symbol, etc). I'm opening the file with notepad if it's that of any significance. A basic outline of my code:
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1->Title = "Save File Here";
saveFileDialog1->RestoreDirectory = true;
if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
{
FileInfo ^fleTest = gcnew FileInfo(saveFileDialog1->FileName);
StreamWriter ^sWriter = fleTest->CreateText();
sWriter->AutoFlush = true;
double test = 5.635; //Some arbitrary double I made up for test purposes
sWriter->Write(test);
sWriter->Flush();
sWriter->Close();
}
Thanks for your help!
Have you tried to set the encoding explicitly?
StreamWriter^ sWriter = gcnew StreamWriter(saveFileDialog1->FileName, false, System::Text::Encoding::ASCII);
The code you've provided does exactly what you ask it to, that is to write a double to the file in the internal computer format. What you most likely want it to write out the textual representation of the double.
In other words you should try sWriter->Write(test.ToString()) or some variation over this, to get the textual version of your double. This also applies to bool and most other variable representation.
i would like create the project, reading from Excel and write on pdf and print this pdf.
From Excel file (from cell) read directory where is original pdf on computer or server, and next cell have info what write on the top in second pdf.
And problem is here, original pdf is horizontal, landscape, rotate and my program create copy from original pdf and write info from excel on the top on copy pdf file. But pdf which is landscape is rotate for 270 deegres. This is no OK. For portrait rotation working program OK, copy OK and write on the top of the copy is OK.
Where is my problem in my code.
Code:
public int urediPDF(string inTekst)
{
if (inTekst != "0")
{
string pisava_arialBD = #"..\debug\arial.ttf";
string oldFile = null;
string inText = null;
string indeks = null;
//razbitje stringa
string[] vhod = inTekst.Split('#');
oldFile = vhod[0];
inText = vhod[1];
indeks = vhod[2];
string newFile = #"c:\da\2";
//odpre bralnik pdf
PdfReader reader = new PdfReader(oldFile);
Rectangle size = reader.GetPageSizeWithRotation(reader.NumberOfPages);
Document document = new Document(size);
//odpre zapisovalnik pdf
FileStream fs = new FileStream(newFile + "-" + indeks + ".pdf", FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
//document.Open();
document.OpenDocument();
label2.Text = ("Status: " + reader.GetPageRotation(reader.NumberOfPages).ToString());
//določi sejo ustvarjanje pdf
PdfContentByte cb = writer.DirectContent;
//izbira pisave oblike
BaseFont bf = BaseFont.CreateFont(pisava_arialBD, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.RED);
cb.SetFontAndSize(bf, 8);
//pisanje teksta v pdf
cb.BeginText();
string text = inText;
//izbira koordinat za zapis pravilnega teksta v pdf (720 stopinj roatacija (ležeče) in 90 stopinj (pokončno))
if (reader.GetPageRotation(1) == 720) //ležeča postavitev
{
cb.ShowTextAligned(1, text, 10, 450, 0);
cb.EndText();
}
else //pokončna postavitev
{
cb.ShowTextAligned(1, text + " - pokončen", 10, 750, 0);
cb.EndText();
}
// create the new page and add it to the pdf
PdfImportedPage page = writer.GetImportedPage(reader, reader.NumberOfPages);
cb.AddTemplate(page, 0, 0);
// close the streams and voilá the file should be changed :)
document.Close();
fs.Close();
writer.Close();
reader.Close();
}
else
{
label2.Text = "Status: Končano zapisovanje";
return 0;
}
return 0;
}
Picture fake pdf:
As explained many times before (ITextSharp include all pages from the input file, Itext pdf Merge : Document overflow outside pdf (Text truncated) page and not displaying, and so on), you should read chapter 6 of my book iText in Action (you can find the C# version of the examples here).
You are using a combination of Document, PdfWriter and PdfImportedPage to split a PDF. Please tell me who made you do it this way, so that I can curse the person who inspired you (because I've answered this question hundreds of times before, and I'm getting tired of repeating myself). These classes aren't a good choice for that job:
you lose all interactivity,
you need to rotate the content yourself if the page is in landscape,
you need to take the original page size into account,
...
Your problem is similar to this one itextsharp: unexpected elements on copied pages. Is there any reason why you didn't read the documentation? If you say: "I didn't have the time", please believe me if I say that I have almost 20 years of experience as a developer, and I've never seen "reading documentation" as a waste of time.
Long story short: read the documentation, replace PdfWriter with PdfCopy, replace AddTemplate() with AddPage().
I have an NSMutableArray with some NSString items . The problem is that , the string items contains some white spaces in the path name . how to remove the extra space in these strings . I manually replaced the white space with the '%20' like this
http://mysites/livingrom/quaba%20mcose%2001_12.jpg
But how to replace all the white spaces from the items in my array .
NSString *pic1 = http://mysites/livingrom/quaba mcose 01_12.jpg
NSString *pic2 = http://mysites/livingrom/quaba mcose 01_13.jpg
NSString *pic3 = http://mysites/livingrom/quaba mcose 01_14.jpg
NSString *pic4 = http://mysites/livingrom/quaba mcose 01_15.jpg
Try this with all the NSStrings:
[pic1 replaceOccurrencesOfString:#" " withString:#""];
I'm not sure if this will work, I've only used it to replace strings when reading from files. It's worth a try though.
My current code is
NSNumberFormatter *f = [[[NSNumberFormatter alloc] init] autorelease];
[f setNumberStyle:NSNumberFormatterCurrencyStyle];
[f setCurrencySymbol:NSLocalizedString(#"CURRENCY", #"Get Currency")];
NSString * stringCurrecy = [f stringFromNumber:(-70.00)];
I'm using NSLog to check the string currency and it's printing "($ 70.00)".
I changed "(", ")" symbol. How can I achieve this:
( $ 70.00 ) -> - $70.00 or $ -70.00
You have to set the negative format.
Add this line:
[f setNegativeFormat:#"-¤#,##0.00"];
but maybe you just want to set the locale with [f setLocale:] instead of setting every format option on your own.
(and next time post code that does compile.)
I have a NSNumber category that does this:
#implementation NSNumber (Formatter)
- (NSString *)currencyStringValue
{
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.locale = [NSLocale currentLocale];
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
formatter.negativePrefix = [NSString stringWithFormat:#"- %#", formatter.currencySymbol];
formatter.negativeSuffix = #"";
return [formatter stringFromNumber:self];
}
#end
Setting negativeFormat to "-" almost worked for me, but it was dropping off the currency symbol. At least for en_US locale, this fits my needs:
NSLocale *US = [NSLocale localeWithLocaleIdentifier:#"en_US"];
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setCurrencyCode:currencyCode];
[currencyFormatter setLocale:priceLocale];
//manually add - prefix to positive format...
NSString *negFormat = [NSString stringWithFormat:#"-%#",currencyFormatter.positiveFormat];
[currencyFormatter setNegativeFormat:negFormat];
I'm not sure whether this is appropriate for all locales, but it works for en_US.