| Thread overview | |||||
|---|---|---|---|---|---|
|
March 29, 2005 writefln not liking % in strings!? | ||||
|---|---|---|---|---|
| ||||
Testing ASCII chars above 128 (testing my translation code), I wrote this little test:
char[] test;
test.length=256;
for(int i=0; i<=255; i++)
test[i] = cast(char) i;
// Checks char by char, and offsets them to "good" chars
remove_q1_Color_Names(test);
printf("\nLine: >%.*s<\n\n",test[1..$]);
writefln("Line: >",test[1..$]);
This yields the following result fro printf:
Line: > []0123456789.<=> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ <=> []0123456789.<=> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ <
printf dumps the translated chars as planned.
Line: > []0123456789.<=> !"#$Error: std.format
% messes up code
writefln on the other hand exits on the % character.
This is more of a warning to the writefln fans. Avoid using it for situations where a % *can* be part of a string you try to output. Ugly!
Back to prinft() for me again. Luckily when translating my code I kept printf() most of the time.
AEon
| ||||
March 29, 2005 Re: writefln not liking % in strings!? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to AEon | AEon wrote: > writefln on the other hand exits on the % character. Unless you write "%%", which is the way to output a % character. > This is more of a warning to the writefln fans. Avoid using it for situations where a % *can* be part of a string you try to output. Ugly! You just need to add a "%s" format, before the string itself... Reasons like this are exactly why I wrote std.stdio.writeln It doesn't have any such "special" characters, like % or so. --anders | |||
March 30, 2005 Re: writefln not liking % in strings!? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote: >> writefln on the other hand exits on the % character. > > Unless you write "%%", which is the way to output a % character. Right, but since I am normally reading string from text files, a % would require a converttion to %%. >> This is more of a warning to the writefln fans. Avoid using it for situations where a % *can* be part of a string you try to output. Ugly! > > You just need to add a "%s" format, before the string itself... Ahh... ops... lazy me! > Reasons like this are exactly why I wrote std.stdio.writeln > It doesn't have any such "special" characters, like % or so. :) AEon | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply