Expression Interpolation in String Literals

This section describes expression interpolation in 'string' literals.

Expression interpolation is supported using the following escape sequence in string literals.

If \ is followed by (...), everything enclosed in the round brackets is evaluated as string(...), and the resulting string will included in the string literal.

Examples of expression interpolations in string literals:

name = "John Doe";

# using expression interpolation
write("Hello \(name), how are you?");

# using the addition operation 
# same result as above, but less readable
write("Hello "+name+", how are you?");

# using expression interpolation
# readability is not very good
write("1-2*3/4 = \(1-2*3/4)");

# using the addition operation 
# readability is not any better
write("1-2*3/4 = "+(1-2*3/4));

# adding a variable
# readability is much better
result = 1-2*3/4;
write("1-2*3/4 = \(result)");

Last update: 2017.

Table of Contents

 About This Book

 Introduction of H Language


 Data Types




 "boolean" Data Type

 "integer" Data Type

"string" Data Type

 What Is "string" Data Type

 "string" Literals

 Escape Sequences in "string" Literals

 Escape Sequences for Non-Printable ASCII Characters

 Escape Sequences for Unicode Characters

 String Literals with Line Breaks

 String Literals Continuing on Next Lines

Expression Interpolation in String Literals

 String Literals with No Escape Sequences

 Constructor Function: string()

 string.get() - Retrieve Character from String

 x[i] - Array Element Format for string.get()

 string.set() - Update Character to String

 x[i] - Array Element Format for string.set()

 "string" "add" Operation

 "string" "subtraction" Operation

 "string" "multiplication" Operation

 "string" "division" Operation

 "string" "modulo" Operation

 string.length() Function

 "real" Data Type

 "array" Data Type

 Source Code Packages

 Classes and Objects

 Object Oriented Programming

 Inheritance - Object Attachments

 Encapsulation - Private Members


 PDF Printing Version