SQL Server에서 데이터를 읽고 텍스트 파일에 쓰는 vb6 프로그램이 있습니다. 각 레코드는 개행 문자로 구분됩니다. 이러한 파일 (200MB 이상일 수도 있음)은 sqlite 데이터베이스에서 iPad로 읽고 써야합니다. 메모리 경고를 피하기 위해 나는 C에서이 기능을 사용하여 파일의 모든 한 줄을 읽어ios에서 C로 큰 텍스트 파일 읽기
"strRet는" 가 이
"는 NSString * stringa"입니다 문자열 C가
있는 NSString으로 변환 C 에서 읽은 문자열입니다NSDictionary *readLineAsNSString(FILE *f,int pospass,BOOL testata,int primorecord )
{
char *strRet = malloc(BUFSIZ);//(char *) togliere perche con c potrebbe restituire un int
if (strRet==NULL)
{
return nil;
}
int size = BUFSIZ;
BOOL finito=NO;
int pos = 0;
int c;
fseek(f,pospass,SEEK_SET);
do{ // read one line
c = fgetc(f);
if (pos >= size-1)
{
size=size+BUFSIZ;
strRet = realloc(strRet, size);
if (strRet==NULL)
{
return nil;
}
}
if(c != EOF)
{
strRet[pos] = c;
pos=pos+1;
}
else
{
finito=YES;
}
}while(c != EOF && c != '\n');
if (pos!=0)
{
strRet[pos] = '\0';
}
NSString *stringa=[NSString stringWithCString:strRet encoding:NSASCIIStringEncoding];
if (pos==0)
{
[email protected]"";
}
long long sizerecord;
if (pos!=0)
{
sizerecord= (long long) [[NSString stringWithFormat:@"%ld",sizeof(char)*(pos)] longLongValue];
}
else
{
sizerecord=0;
}
pos = pospass + pos;
NSDictionary *risultatoc = @{st_risultatofunzione: stringa,
st_criterio: [NSString stringWithFormat:@"%d",pos],
st_finito: [NSNumber numberWithBool:finito],
st_size: [NSNumber numberWithLongLong: sizerecord]
};
//Svuoto il buffer
free(strRet);
// free(tmpStr);
strRet=NULL;
return risultatoc;
}
그러나 파일에 특수 문자가있는 경우 (예 : € 기호 나 악센트 부호가있는 문자 또는 일부 북유럽 국가) 레코드가 올바르게 읽히지 않으며 NSString을 임의로 찾습니다. 문자 대신에 당신이 나를 도와 줍니까? 고맙습니다!
NSString *stringa= [NSString stringWithCString:strRet encoding:NSASCIIStringEncoding];
그러나, € 기호 또는 악센트 문자가 ASCII의 일부가 아닌 :
'stringWithCString : encoding' 메소드에서'encoding'을'NSWindowsCP1252StringEncoding'으로 변경하십시오. http://www.madore.org/~david/computers/unicode/cstab.html#CP1252 – bobnoble