Swan Lake Beta3 is here.
import ballerina/io;

public function main() {
    // String literals use double quotes. You can use usual C escapes such as `\t \n`.
    // Numeric escapes specify Unicode code point using one or more hex digits `\u{H}`.
    string grin = "\u{1F600}";

    // String concatenation uses `+` operator.
    string greeting = "Hello" + grin;

    io:println(greeting);

    // `greeting[1]` accesses character at index 1 (zero-based).
    io:println(greeting[1]);

}

Strings

The string type represents immutable sequence of zero or more Unicode characters. There is no separate character type: a character is represented by a string of length 1. Two string values are == if both sequences have the same characters. You can use <, <=, >, and >= operators on string values and they work by comparing code points. Unpaired surrogates are not allowed.

import ballerina/io;
public function main() {
    string grin = "\u{1F600}";

String literals use double quotes. You can use usual C escapes such as \t \n. Numeric escapes specify Unicode code point using one or more hex digits \u{H}.

    string greeting = "Hello" + grin;

String concatenation uses + operator.

    io:println(greeting);
    io:println(greeting[1]);

greeting[1] accesses character at index 1 (zero-based).

}
bal run strings.bal
Hello๐Ÿ˜€
e
import ballerina/io;

public function main() {
    // String literals use double quotes. You can use usual C escapes such as `\t \n`.
    // Numeric escapes specify Unicode code point using one or more hex digits `\u{H}`.
    string grin = "\u{1F600}";

    // String concatenation uses `+` operator.
    string greeting = "Hello" + grin;

    io:println(greeting);

    // `greeting[1]` accesses character at index 1 (zero-based).
    io:println(greeting[1]);

}

Strings

The string type represents immutable sequence of zero or more Unicode characters. There is no separate character type: a character is represented by a string of length 1. Two string values are == if both sequences have the same characters. You can use <, <=, >, and >= operators on string values and they work by comparing code points. Unpaired surrogates are not allowed.

import ballerina/io;
public function main() {
    string grin = "\u{1F600}";

String literals use double quotes. You can use usual C escapes such as \t \n. Numeric escapes specify Unicode code point using one or more hex digits \u{H}.

    string greeting = "Hello" + grin;

String concatenation uses + operator.

    io:println(greeting);
    io:println(greeting[1]);

greeting[1] accesses character at index 1 (zero-based).

}
bal run strings.bal
Hello๐Ÿ˜€
e
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand