Positron Compiler Documentation

Right$

Source: Positron16 Compiler User Manual, PDF page 369

Syntax

Destination String = Right$ (Source String, Amount of characters)

Overview

Extract n amount of characters from the right of a source string and copy them into a destination string.

Overview

Destination String can only be a String variable, and should be large enough to hold the correct amount of characters extracted from the Source String. Source String can be a String variable, or a Quoted String of Characters. See below for more variable types that can be used for Source String. Amount of characters can be any valid variable type, expression or constant value, that signifies the amount of characters to extract from the right of the Source String. Values start at 1 for the rightmost part of the string and should not exceed 255 which is the maximum allowable length of a String variable.

Example 1

' Copy 5 characters from the right of SourceString into DestString
'
  Device = 24HJ128GP502
                                     ' Select the device to compile for
  Declare Xtal = 16
  Dim SourceString as String * 20
                                     ' Create a String of 20 characters
  Dim DestString as String * 20
                                     ' Create another String
  SourceString = "Hello World"
                                     ' Load the source string with characters
'
' Copy 5 characters from the source string into the destination string
'
  DestString = Right$ (SourceString, 5)
  Print DestString
                         ' Display the result, which will be "World"

Example 2

' Copy 5 characters from right of a Quoted Character String to DestString
'
  Device = 24HJ128GP502
                                     ' Select the device to compile for
  Declare Xtal = 16
  Dim DestString as String * 20
                                     ' Create a String of 20 characters
'
' Copy 5 characters from the quoted string into the destination string
'
  DestString = Right$ ("Hello World", 5)
  Print DestString
                         ' Display the result, which will be "World"

The Source String can also be a Byte, Word, Dword, Float or Array, variable, in which case the value contained within the variable is used as a pointer to the start of the Source String's address in RAM.

Example 3

' Copy 5 characters from the right of SourceString into DestString using a
' pointer to SourceString
  Device = 24HJ128GP502
                                     ' Select the device to compile for
  Declare Xtal = 16
  Dim SourceString as String * 20
                                     ' Create a String of 20 characters
  Dim DestString as String * 20
                                     ' Create another String
' Create a Word variable to hold the address of SourceString
  Dim StringAddr as Word
  SourceString = "Hello World"
                                     ' Load the source string with characters
'
' Locate the start address of SourceString in RAM
'
  StringAddr = AddressOf(SourceString)
'
' Copy 5 characters from the source string into the destination string
'
  DestString = Right$(StringAddr, 5)
  Print DestString
                                     ' Display the result, which will be "World"

A third possibility for Source String is a Label name, in which case a null terminated Quoted String of Characters is read from code memory.

Example 4

' Copy 5 characters from the right of a code memory string into DestString
'
  Device = 24HJ128GP502
                                     ' Select the device to compile for
  Declare Xtal = 16
  Dim DestString as String * 20
                                     ' Create a String of 20 characters
'
' Create a null terminated string of characters in code memory
'
  Dim Source as Code = "Hello World", 0
'
' Copy 5 characters from label Source into the destination string
'
  DestString = Right$(Source, 5)
  Print DestString
                                     ' Display the result, which will be "World"

See also : Creating and using Strings, Creating and using code memory strings,

Len, Left$, Mid$, Str$, ToLower, ToUpper, AddressOf.