17. Mai 2016 14:40
File.WRITE('mein Text') | ein CRLF (13 + 10) |
OutStream.WRITETEXT('mein Text") | nichts - übrigens unabhängig davon, ob die Datei mit oder Textmode geöffnet ist. |
OutStream.WRITE("mein Text") | ein NULL (hexadezimal 00) an. Wieder unabhängig vom Textmode. |
NewEncoding := TEXTENCODING::UTF8;
FolderName := 'UTF8';
// File.WRITE schließt immer mit einem CRLF ab
TestFile.TEXTMODE := TRUE;
TestFile.CREATE('C:\Temp\' + FolderName + '\OhneTextmode_2Umlaute.txt',NewEncoding);
TestFile.WRITE('äöüß'); // + CRLF
TestFile.CLOSE;
// OutStream.WRITE fügt nach jedem WRITE an NULL (00) an. Textmode egal!
TestFile.TEXTMODE := TRUE;
TestFile.CREATE('C:\Temp\' + FolderName + '\OhneTextmode_2Umlaute_Streaming_TextmodeTRUE_WRITE.txt',NewEncoding);
TestFile.CREATEOUTSTREAM(NAVOutStream);
NAVOutStream.WRITE('äöüß'); // + NULL
TestFile.CLOSE;
TestFile.TEXTMODE := FALSE;
TestFile.CREATE('C:\Temp\' + FolderName + '\OhneTextmode_2Umlaute_Streaming_TextmodeFALSE_WRITE.txt',NewEncoding);
TestFile.CREATEOUTSTREAM(NAVOutStream);
NAVOutStream.WRITE('äöüß'); // + NULL
TestFile.CLOSE;
// OutStream.WRITETEXT fügt nichts mehr an - so wie es sein soll. Textmode egal!
TestFile.TEXTMODE := TRUE;
TestFile.CREATE('C:\Temp\' + FolderName + '\OhneTextmode_2Umlaute_Streaming_TextmodeTRUE_WRITETEXT.txt',NewEncoding);
TestFile.CREATEOUTSTREAM(NAVOutStream);
NAVOutStream.WRITETEXT('äöüß'); // + gar nichts
TestFile.CLOSE;
TestFile.TEXTMODE := FALSE;
TestFile.CREATE('C:\Temp\' + FolderName + '\OhneTextmode_2Umlaute_Streaming_TextmodeFALSE_WRITETEXT.txt',NewEncoding);
TestFile.CREATEOUTSTREAM(NAVOutStream);
NAVOutStream.WRITETEXT('äöüß'); // + gar nichts
TestFile.CLOSE;
19. Mai 2016 13:19
Hat echt niemand eine Meinung dazu?Natalie hat geschrieben:Ist das jetzt ein Bug oder ein Feature?
23. Mai 2016 12:47
For example, a string is defined as a pointer to char in the C language, and is conventionally terminated with a NULL character. In object-ori-
ented languages, a string is a complex object, with associated methods, and its value may or may not consist of merely a code unit sequence.
In Modified UTF-8 the null character (U+0000) is encoded as 0xC0,0x80. Modified UTF-8 strings never contain any actual null bytes but can contain all Unicode code
points including U+0000
Some systems use "modified UTF-8" which encodes the NUL character as two non-zero bytes (0xC0, 0x80) and thus allow all possible strings to be stored. (this is not allowed by the UTF-8 standard as it is a security risk. A C0,80 NUL might be seen as a string terminator in security validation and as a character when used)
23. Mai 2016 13:20
23. Mai 2016 16:49
Natalie hat geschrieben:OK danke, ich nehme das mal zum Anlass, es doch Microsoft zu melden - Supportfall 116052314197082. Ich halte euch auf dem Laufenden.
23. Mai 2016 16:56
Der Vorschlag mit WRITETEXT kam auch schonwinfy hat geschrieben:"Nimm doch NAVOutStream.WRITETEXT" und die Anderen, die einen null-terminierten String möchten, nehmen NAVOutStream.WRITE - Problem gelöst.
26. Mai 2016 16:29
29. Juni 2016 09:16
However, bare in mind that there are 2 ways of writting and 2 ways of reading Streams: binary and text wised. So, whenever you are using OutStream.Write, you are writting binary, and when using OutStream.WriteTEXT, you are, literally writting only the text part of the parameter.
So, when using READ, versus READTEXT, you will be seeking for the NULL termination that the binary text will WRITE out. That is why you will get an AL error if this NULL termination was not found.
[...] strings in NAV are containing their length in the first character. So, they are not null-terminated. [...] With an outstream variable you will get the null-terminated string / zero byte as EOS if you use OutS.WRITE.
MS Developers hat geschrieben:Chars in AL are by default two bytes [seit NAV 2013]. The NULLs written between each of the characters of the string are just the lower/higher byte of the character retrieved from the string.
As a work-around, assign a byte variable to the value of the character extracted from the string and write that. (Beispiel: siehe Byte Data Type) This will cause the byte sequence to be written to the stream without any injected zeros (NULLs).
MS Support hat geschrieben:I think NAV 2009 chars had 1 byte and only current NAV becomes Unicode (2 bytes). So NAV 2009 just didn’t need NULL.
24. Januar 2017 10:31
Function RemoveNULLs
{
## No blank line at the end, keeps LF for Unix/Linux Systems
$sourceEncoding = [System.Text.Encoding]::GetEncoding(850)
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$args = resolve-path $args
$filecontent = [System.IO.File]::ReadAllText($args,$sourceencoding).Replace("`0","")
[System.IO.File]::WriteAllText($args, $filecontent,$targetEncoding)
}
Function RemoveNULLs2
{
### Adds blank line at the end and converts LF to CR LF
(Get-Content $args -encoding Oem) -replace "`0", "" | Set-Content $args -encoding Oem
}