digitalmars.D.learn - How to use readText to read utf16 file?
- Domain (1/1) Nov 16 2015 How to use readText to read utf16 file? Or other encoding file.
- Adam D. Ruppe (6/7) Nov 16 2015 readText!wstring("filename")
- Domain (2/10) Nov 16 2015 Thanks! But how to remove BOM? Slice the result myself?
- Adam D. Ruppe (3/4) Nov 16 2015 Yeah. Do something like if(result.length &&result[0] == bom) {
- Steven Schveighoffer (5/9) Nov 16 2015 To be technically correct, you can do:
- Gary Willoughby (3/4) Nov 17 2015 Here's a helpful resource when working with text files in D.
- Emil Perhinschi (4/8) Jun 21 2021 the nomad.so site is now about minecraft, the old content here:
How to use readText to read utf16 file? Or other encoding file.
Nov 16 2015
On Tuesday, 17 November 2015 at 02:40:14 UTC, Domain wrote:How to use readText to read utf16 file?readText!wstring("filename") should do it for utf16. It will return a wstring, which is utf-16. You can do utf32 with readText!dstring. The default, of course, is string, which is utf8. It doesn't support conversions or any other encoding.
Nov 16 2015
On Tuesday, 17 November 2015 at 02:42:29 UTC, Adam D. Ruppe wrote:On Tuesday, 17 November 2015 at 02:40:14 UTC, Domain wrote:Thanks! But how to remove BOM? Slice the result myself?How to use readText to read utf16 file?readText!wstring("filename") should do it for utf16. It will return a wstring, which is utf-16. You can do utf32 with readText!dstring. The default, of course, is string, which is utf8. It doesn't support conversions or any other encoding.
Nov 16 2015
On Tuesday, 17 November 2015 at 02:50:44 UTC, Domain wrote:Thanks! But how to remove BOM? Slice the result myself?Yeah. Do something like if(result.length &&result[0] == bom) { result = result[1..$]; } and you'll have it.
Nov 16 2015
On 11/16/15 10:00 PM, Adam D. Ruppe wrote:On Tuesday, 17 November 2015 at 02:50:44 UTC, Domain wrote:To be technically correct, you can do: if(!result.empty && result.front == bom) result.popFront(); This should work for all 3 types of strings. -SteveThanks! But how to remove BOM? Slice the result myself?Yeah. Do something like if(result.length &&result[0] == bom) { result = result[1..$]; } and you'll have it.
Nov 16 2015
On Tuesday, 17 November 2015 at 03:12:47 UTC, Steven Schveighoffer wrote:On 11/16/15 10:00 PM, Adam D. Ruppe wrote:Thank you! Now another question: how to handle endianness?On Tuesday, 17 November 2015 at 02:50:44 UTC, Domain wrote:To be technically correct, you can do: if(!result.empty && result.front == bom) result.popFront(); This should work for all 3 types of strings. -SteveThanks! But how to remove BOM? Slice the result myself?Yeah. Do something like if(result.length &&result[0] == bom) { result = result[1..$]; } and you'll have it.
Nov 16 2015
On Tuesday, 17 November 2015 at 05:37:55 UTC, Domain wrote:Thank you! Now another question: how to handle endianness?If your file follow a file format: the endianness should be defined there. else it's a random text file: either it will have a BOM with endianness, or you will have to guess.
Nov 17 2015
On Tuesday, 17 November 2015 at 02:40:14 UTC, Domain wrote:How to use readText to read utf16 file? Or other encoding file.Here's a helpful resource when working with text files in D. http://nomad.so/2015/09/working-with-files-in-the-d-programming-language/
Nov 17 2015
On Tuesday, 17 November 2015 at 13:00:11 UTC, Gary Willoughby wrote:On Tuesday, 17 November 2015 at 02:40:14 UTC, Domain wrote:the nomad.so site is now about minecraft, the old content here: https://web.archive.org/web/20171109072958/http://nomad.so/2015/09/working-with-files-in-the-d-programming-language/How to use readText to read utf16 file? Or other encoding file.Here's a helpful resource when working with text files in D. http://nomad.so/2015/09/working-with-files-in-the-d-programming-language/
Jun 21 2021