Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2024/25/2
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Strings are immutable

See also std.conv.

(1) immutability
def main():
    s = "hello"
    print(s[0])  # 'h'
    s[0] = "H"  # Error!
import std.stdio;

void main()
{
    string s = "hello";
    writeln(s[0]); // 'h'
    s[0] = 'H'; // Error!
}

String length

(2) length of a string
def main():
    s = "Éva"
    print(len(s))  # 3, number of chars
import std.stdio;
import std.conv;  // to()

void main()
{
    string s = "Éva"; // stored in UTF-8
    writeln(s.length); // 4, number of bytes

    writeln(s.to!dstring.length); // 3
}

dstring uses UTF-32 encoding, thus every character occupies 4 bytes. But in 4 bytes every Unicode character can be stored.

String concatenation

(3) concatenation
def main():
    s = "aa"
    t = s
    print(s)  # aa
    s += "bb"
    print(s)  # aabb
    print(t)  # aa
import std.stdio;

void main()
{
    string s = "aa";
    string t = s;
    writeln(s); // aa
    s ~= "bb";
    writeln(s); // aabb
    writeln(t); // aa
}

D uses the '~' sign for concatenation.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2025 June 27, 12:21