What is 0xdb8844? - iphone

I am reading a text file into an NSArray as below:
Hi.This is the first line.
--blank line--
Hey, this is the second line.
--blank line--
...
This NSArray reads every line including a blank line just like the above, but I find
this 0xdb8844 in the second element of the NSArray. I think it represents a blank line
in hexadecimal or UTF-8. Can any one tell me how to decode this?
Thank you for your time.

That is the memory address of the element stored in the array.
If you want to see what is stored there, add the following line after you read in the text file:
NSLog(#"Array element 1: '%#'.", [array objectAtIndex:1]);
It probably is the blank line, based on what you have here, and will print the following log statement which indicates that it is indeed the blank line:
Array element 1: ''.

Related

Postgres: Inconsistent reported row numbers by failed Copy error

I have a file foo that I'd like to copy into a table.
\copy stage.from_csv FROM '/path/foo.dat' CSV;
If foo has an error like column mismatch or bad type, the return error is normal:
CONTEXT: COPY from_csv, line 5, column report_year: "aa"
However, if the error is caused by an extraneous quotation mark, the reported line number is always one greater than the size of the file.
CONTEXT: COPY from_csv, line 11: "02,2004,"05","123","09228","00","SUSX","PR",30,,..."
The source file has 10 lines, and I placed the error in line 5. If you examine the information in the CONTEXT message, it contains the line 5 data, so I know postgres can identify the row itself. However, it cannot identify the row by number. I have done this with a few different file lengths and the returned line number behavior is consistent.
Anyone know the cause and/or how to get around this?
That is because the error manifests only at the end of the file.
Look at this CSV file:
"google","growing",1,2
"google","growing",2,3
"google","falling","3,4
"google","growing",4,5
"yahoo","growing",1,2
There is a bug in the third line, an extra " has been added before the 3.
Now to parse a CSV file, you first read until you hit the next line break.
But be careful, line breaks that are within double quotes don't count!
So all of the line breaks are part of a quoted string, and the line continues until the end of file.
Now that we have read our line, we can continue parsing it and notice that the number of quotes is unbalanced. Hence the error message:
ERROR: unterminated CSV quoted field
CONTEXT: COPY stock, line 6: ""google","falling","3,4
"google","growing",4,5
"yahoo","growing",1,2
"
In a nutshell: the error does not occur until we have reached the end of file.

If Line Number Exists

Im trying to get a code that will do something if a certain line number is in a text file for example "Test.txt"
Ex.
if line "x" exists in test.txt msg $chan working
thanks #denny for being the one to help me out.
if ($read(test.txt, n, x)) {
msg $chan working
}
You have couple of options.
Searching to see if the number is lower or equal to the total lines. e.g: $lines(filename)
You can extract the line and use a condition if it's full. e.g: $read(filename, LINE-NUMBER)
Notes for each method:
Will only tell you if there is a line number, NOT if there is something inside this line.
Will only give you the line if exists, if the line is empty or there is no such line then it will appears like it's empty.

Matlab: Printing literally using fprintf

I am writing a Matlab function that does some file manipulation as follows. I take the input file, read it line by line and write it to an output file. If the line contains a keyword, I do some further processing before writing the output. My problem is this: If the input line contains an escape character, it messes up the fprintf that I use to write the output. For example, if the input line contains a % sign, the rest of the line does not show up in the output. So, my question is: is there a way to force fprintf to ignore all escape sequences and print the literal string? Thanks in advance for the help.
Sample code below:
fptr_read = fopen('read_file.txt','r'); fptr_write = fopen('write_file.txt','w');
while(~feof(fptr_read))
current_line = fgetl(fptr_read);
fprintf(fptr_write,current_line);
end
If current_line looks like 'Gain is 5% larger', it will get written as 'Gain is 5'. I want the line reproduced verbatim without manually having to check for presence of escape characters.
I had a similar problem once, and solved it like this:
fprintf(fp,'%s',stringWithEscapesIWant)

how to have next line exporting csv file in iphone

How to give next line in row value if I have multiple value in one row and show in exporting csv file .
I want add text as new line this code is doing well, but I have multiple value in one row then it does not print that row, it only prints another row. How to solve this problem
buffer is string.
buffer = [buffer stringByAppendingFormat: #"\r\n%#", rowString];
"\n\n" should give you a new line.

How do you read a specific line number from a file in objective-c?

Hoping someone could point me in the right direction on finding how to read given line number(s) from a giant xml file (50k+ lines)?
Since the lines in an XML file don't typically have a fixed length, there's no way to divine where the nth line in your file starts. You'll have to start reading from the beginning and count lines until you find the one that you want.
If you're going to access this file frequently, one thing you might want to do is to build an index for the file. Scan through the file and write the file offset of the beginning of each line into your index file. Since those offsets all have the same size, and since there's one for every line, you can find the offset of the nth line of your data file by reading the nth offset from the index file.
I did it this way:
I first loaded the file in memory (50k+ lines is big, but possible):
// Load file as single string.
// NSISOLatin1StringEncoding works most of the time.
// Use other encoding if necessary.
NSStringEncoding encoding = NSISOLatin1StringEncoding;
NSError *error = nil;
NSString *fileAsString = [NSString stringWithContentsOfFile: path
encoding: encoding
error: &error];
if (error != nil)
NSLog(#"%#", error);
Then I enumerated the lines using this:
__block NSUInteger currentLineNum = 1;
[fileAsString enumerateLinesUsingBlock:
^(NSString *line, BOOL *stop)
{
// Handle line here...
currentLineNum++;
}];
This way you can easily find the line with the number you are looking for.
Perhaps there are better ways, but this works.