Importing Mac txt files into Xojo

Coming from a Mac/Real Studio background I am used to saving data files in txt format and loading them via a textInputStream into an array.

I am trying to write a Xojo program on a PC and have emailed across the txt files I want to input. However, for reasons I don’t understand there are often blank lines between the lines of imported data in the arrays. I can’t see how to remove these from the tables in Notepad. In fact the files look OK in Notepad. I can get around it by telling the program to ignore blank lines when appending to arrays but I’d like to not have to do that.

(The files originate as tables in Word. I save them in text format and check they are plain text in Mac’s TextEdit program with a .txt extension)


Forgot the link and can’t edit:

Can you show us the code you use to load the file?

Thanks Alex, I guess I could do that on the Mac before transferring the file

Kem, I generally define f, i, line and aData() then, having checked f exists while not i.eof line=i.readline aData.append(line) wend i.close

Odd, that should take care of the line endings for you, but try this instead:

i = TextInputStream.Open( f )
dim completeText as string = i.ReadAll
i = nil

completeText = ReplaceLineEndings( completeText, EndOfLine.UNIX )
aData = completeText.Split( EndOfLine.UNIX )

save a bit of memory if the file is big

i = TextInputStream.Open( f )
dim completeText as string =ReplaceLineEndings(i.readall, EndOfLine.UNIX )

I’ll try those. And thanks for these responses. I didn’t realise plain text could be so complex.

Incidentally, I’ve just had to transfer another file from the Mac so I paid attention when I specified I wanted plain text.

Word offered me MacOS, MS-DOS or Other. I think I previously selected Other, because that gave me the opportuity to also select Western (Windows Latin 1), which I thought was the PC equivalent of Mac’s plain text.

What I didn’t notice previously was another setting allowing me to specify four different line endings - CR/LF, CR Only, LF only or LF/CR. I would have left that at the default, I imagine (CR/LF?). What would the correct setting be for a Windows machine?

(Other options were Western ASCII, Unicode 5.1, Unicode 5.1 UTF-8, Unicode 5.1 Little-Endian, Central European Mac and Central European Windows Latin plus some rather more exotic settings for Japanes, Chinese, Turkish etc)

Windows standard is CR-LF, but Xojo won’t care. Or rather, it’s up to you in any event to make sure it’s handled properly.