d - multiplying a string by an integer returns integers? -


So I was trying to create asterisk pyramid using D. At first I saw that the combination seems impossible. Writing something like writeln ("foo" + "bar") will give you a syntax error. Instead, I tried to multiply the string like a dragon, which did not work with double quoted strings, But there is something strange with single quoted stars.

If you type in

  import std.stdio; Zero main () {foreach (i; 0 .. 10) {article (i * '0'); }}   

This will return a bunch of integers. Can anyone explain why this happens? And to tell me how to add a string, it really will be helpful.

Thank you!

'0' is not a string, it is a character that uses ASCII encoding. The number is being multiplied with the integer ID of the encoding. For example, encoding for ASCII's 'A' is 65.

  import std.stdio; Int main () {writeln (cast ('a'); Written (10 * 'A'); Return 0; }   

This program will print 65 and 650 because the character is being converted into integer in both cases.

To resolve the basic closing problem, use 'array1 ~ = array2' to add the array '2' to operator1, or 'array1' in array1, to include two arrays.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -