string.get() - Retrieve Character from String

This section describes string.get() function that retrieves the character from a string at a given location.

A "string" data object can be operated like an array of elements. Each element represents each characters in the string.

string.get() function is provided to retrieve the character represented by the element of a given location using the following syntax:

string.get(a, i)

Parameters:
   a - A "string" data object.
   i - An "integer" data object.

Return: 
   Returns a new "string" data object representing 
   the single character from "a" at the location of "i".
   Location zero, 0, is the first character of the string. 
   
Errors:
   Throws "IndexOutOfBound" error code, if the given integer 
   points to a location outside of the string.

Examples of how to use string.get() function:

string.get("Hello world!", 0); # Returns "H"

y = string("Hello world!"); 
string.get(y, 11); # Returns "!"

string.get(y, 12); # Gets the "IndexOutOfBound" error.

Last update: 2017.

Table of Contents

 About This Book

 Introduction of H Language

 Syntax

 Data Types

 Variables

 Expressions

 Statements

 "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

 References

 PDF Printing Version