From: Tim Kynerd Date: 2003-02-12T18:42:33+09:00 Subject: Re: String frustration On Wed, 12 Feb 2003 14:16:03 +0900, Harry Ohlsen wrote: > A number of people have given you solutions to the problem, so I won't > rehash that. > > However, in case you have misunderstood what was going on, I thought I'd > point out that the two characters '\' and 'n' next to each other in your > text file would never be interpreted as a newline, but always as two > separate characters. > > They would be interpreted as a newline if they appeared in a string in > your source code (as in the replacement text in the gsub() someone > suggested)). > > My apologies if you already understood that! No apologies necessary. I'm not 100% clear on this. Although I think I understand what's going on here, it leaves me wondering what would be a better way to do what I need to do, if there is a better way. The input file contains three tab-separated fields. The second field needs to be able to contain an arbitrary number of newlines (which will be realized as actual newlines, so to speak, when this field is later printed out). The only alternative I can see (to including them as "\n" in the second field) is to actually put the newlines into the file as newlines, so to speak, and specify a different string as the record separator (say, an uncommon character followed by a newline). However, this obviously makes the file rather difficult to create in a text editor, and to read. Then, since there happen to be exactly three fields in each line, there's the idea of tab-separating the "pieces" of the second field, then reading everything in, taking the first and last fields as the first and third, and interpreting everything in between as the second field. This would work, but I don't like it because it depends crucially on the fact that there are exactly three fields per line (and that may not remain true as I continue to play with this program I'm writing). Any other ideas? -- Tim Kynerd Sundbyberg (sm�stan i storstan), Sweden tim@tram.nu Sunrise in Stockholm today: 7:39 Sunset in Stockholm today: 16:24 My rail transit photos at http://www.kynerd.nu