mn8 Language Reference | Index    

String

SUMMARY: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  OPERATORS SUMMARY  METHODS SUMMARYDETAIL: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  OPERATOR DETAILS  METHOD DETAILS

Description

A lexical string constant enclosed in double quotes evaluates to a value of type string. A string consists of a sequence of characters. The number of characters in a string is called its length. The empty string, denoted by "", contains no characters and has a length of zero. There is no limit to the string size. Strings may be wrap across several lines in MN8 programs. Strings may also contain the escape sequences defined in Escape Sequences. Note that escape sequences are not expanded in strings that are written with the back-quote character.

Usage

        String Expressions
            Expression            Value         Value Type
            -----------           -------       ----------
              "abc"                 "abc"         String
              `ab\nc`               "ab\nc"       String
              "abc" + 'd'           "abcd"        String
              "abc".length          3             Integer

Version: 0.1
Authors:Remus Pereni (http://neuro.nolimits.ro)
Location:
Inherits: Concept

Operator List

Logical> (String $value)
String+ (Logical $value)
String+ (Real $value)
String+ (Concept $value)
Logical< (String $value)
String+ (Integer $value)
String+ (Character $value)
String+ (String $value)
Logical== (String $value)
String+ (Nil $value)
top

Method List

CharactercharAt (Integer $index)
IntegercompareTo (String $value)
Logicalcontains (Expression $expr)
Logicalcontains (String $value)
LogicalendsWith (String $value)
LogicalequalsIgnoreCase (String $value)
IntegergetLength
SeriesgetLines
SeriesgetTokens (String $delim)
SeriesgetTokensWithDelimiters (String $delim)
IntegerindexOf (String $value)
IntegerindexOf (String $value, Integer $index)
IntegerlastIndexOf (String $value)
IntegerlastIndexOf (String $valiue, Integer $index)
Logicalmatches (Expression $expr)
Stringreplace (Character $oldChar, Character $newChar)
Seriesselect (Expression $expr)
LogicalstartsWith (String $value)
LogicalstartsWith (String $value, Integer $index)
Stringsubstring (Integer $index, Integer $length)
Stringsubstring (Integer $index)
StringtoLowerCase
StringtoStringConcept
StringtoUpperCase
Stringtrim
Stringwrap (Integer $value)
Stringwrap (Integer $value, String $align)
Stringwrap
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Operator Info

> (String $value)
Parameters:
$value :

top
+ (Logical $value)
Parameters:
$value :

top
+ (Real $value)
Parameters:
$value :

top
+ (Concept $value)
Parameters:
$value :

top
< (String $value)
Parameters:
$value :

top
+ (Integer $value)
Parameters:
$value :

top
+ (Character $value)
Parameters:
$value :

top
+ (String $value)
Parameters:
$value :

top
== (String $value)
Parameters:
$value :To this will be compared this concept.

Returns true if this concept and the concept given as parameter is equal, false otherwise.

top
+ (Nil $value)
Parameters:
$value :

top

Detailed Method Info

charAt (Integer $index)
Parameters:
$index :The index of the character.
Returns: Character

Returns the character at the specified index.

            $str = "This is a test."
            print $str.charAt(3)
            -- the result is --
            i
            

top
compareTo (String $value)
Parameters:
$value :The string to be compared.
Returns: Integer

The value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument and a value greater than 0 if this string is lexicographically greater than the string argument.

            $str = "This is a test."
            print $str.compareTo("This is a text.")
            -- the result is --
            -5
            

top
contains (Expression $expr)
Parameters:
$expr :The expression to be applied to this concept.
Returns: Logical

Returns true if the specified expression match this concept, false otherwise.

            $str = "This is a test."
            print $str.contains(Simplex.create("*s"))
            -- the result is --
            true
            

top
contains (String $value)
Parameters:
$value :String to be searched in this concept.
Returns: Logical

Returns true if the specified string is found in this concept, false otherwise.

            $str = "This is a test."
            print $str.contains("is")
            -- the result is --
            true
            

top
endsWith (String $value)
Parameters:
$value :The suffix.
Returns: Logical

Returns true if the character sequence represented by the parameter is a suffix of the character sequence represented by this concept, false otherwise.

            $str = "This is a test."
            print $str.endsWith("st.")
            -- the result is --
            true
            

top
equalsIgnoreCase (String $value)
Parameters:
$value :The string to compare this concept against.
Returns: Logical

Returns true if the parameter and this concept are equal, ignoring case, false otherwise.

            $str = "This is a test."
            print $str.equalsIgnoreCase("tHiS iS a TesT.")
            -- the result is --
            true
            

top
getLength
Returns: Integer

Returns a integer concept representing this concept length.

            $str = "This is a test."
            print $str.getLength
            -- the result is --
            15
            

top
getLines
Returns: Series

Returnes a series with lines from this concept. Where the "\n" character is found there begins the new line. If not found any "\n" character then the returned series will contain a single element which represents this concept.

            $str = "This is\n a test."
            print $str.getLines
            -- the result is --
            This is
            a test.
            

top
getTokens (String $delim)
Parameters:
$delim :The delimiter.
Returns: Series

Returns a series which contains the tokens of this concept, tokenized by the specified delimiter. Delimiter will not be treated as token.

            $str = "This is a test."
            print $str.getTokens(" ")
            -- the result is --
            This
            is
            a
            test.
            

top
getTokensWithDelimiters (String $delim)
Parameters:
$delim :The delimiter.
Returns: Series

Returns a series which contains the tokens of this concept, tokenized by the specified delimiter, the delimiter is returned as a token.

            $str = "This is a test."
            print $str.getTokensWithDelimiters(" ")
            -- the result is --
            This

            is

            a

            test.
            

top
indexOf (String $value)
Parameters:
$value :Any string.
Returns: Integer

If the string argument occurs as a substring within this concept, then the index of the first character of the first such substring is returned if it does not occur as a substring, -1 is returned.

            $str = "This is a test."
            print $str.indexOf("is")
            -- the result is --
            3
            

top
indexOf (String $value, Integer $index)
Parameters:
$value :Any string.
$index :The index to start the search from.
Returns: Integer

If the string argument occurs as a substring within this object and the starting index no smaller than fromIndex, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.

            $str = "This is a test."
            print $str.indexOf("is", 4)
            -- the result is --
            6
            

top
lastIndexOf (String $value)
Parameters:
$value :Any string.
Returns: Integer

If the string argument occurs one or more times as a substring within this concept, then the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned.

            $str = "This is a test."
            print $str.lastIndexOf("is")
            -- the result is --
            6
            

top
lastIndexOf (String $valiue, Integer $index)
Parameters:
$valiue :Any string.
$index :The index to start the search from.
Returns: Integer

If the string argument occurs one or more times as a substring within this concept at a starting index no greater than fromIndex, then the index of the first character of the last such substring is returned. If it does not occur as a substring starting at fromIndex or earlier, -1 is returned.

            $str = "This is a test."
            print $str.lastIndexOf("is", 4)
            -- the result is --
            3
            

top
matches (Expression $expr)
Parameters:
$expr :The expression to be applied to this concept.
Returns: Logical

Returns true if the specified expression match this concept, false otherwise.

            $str = "This is a test."
            print $str.matches(Simplex.create("*is*"))
            -- the result is --
            true
            

top
replace (Character $oldChar, Character $newChar)
Parameters:
$oldChar :The oldChar to be replaced.
$newChar :The newChar with which will be replaced.
Returns: String

If the character oldChar does not occur in the character sequence represented by this concept, then a reference to this concept is returned. Otherwise, a new string concept is created that represents a character sequence identical to the character sequence represented by this string concept, except that every occurrence of oldChar is replaced by an occurrence of newChar.

            $str = "This is a test."
            print $str.replace('s', 'x')
            -- the result is --
            Thix ix a text.
            

top
select (Expression $expr)
Parameters:
$expr :The expression to be applied to this concept.
Returns: Series

Select that portion from this concept which match the specified expression.

            $str = "This is a test."
            print $str.select(Simplex.create("*s"))
            -- the result is --
            This
            is
            

top
startsWith (String $value)
Parameters:
$value :The prefix.
Returns: Logical

Returns true if the character sequence represented by the argument is a prefix of the character sequence represented by this string concept, false otherwise.

            $str = "This is the test."
            print $str.endsWith("th")
            -- the result is --
            true
            

top
startsWith (String $value, Integer $index)
Parameters:
$value :The prefix.
$index :From where to begin looking in the string.
Returns: Logical

Returns true if the character sequence represented by the argument is a prefix of the substring of this object starting at index given as parameter, false otherwise.

            $str = "This is the test."
            print $str.startsWith("th", 9)
            -- the result is --
            true
            

top
substring (Integer $index, Integer $length)
Parameters:
$index :The begining index, inclusive.
$length :The ending index, exclusive.
Returns: String

Returns a new string concept that is a substring of this string concept. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

            $str = "This is a test."
            print $str.substring(6, 10)
            -- the result is --
            is a
            

top
substring (Integer $index)
Parameters:
$index :The begining index, inclusive.
Returns: String

Returns a new string concept that is a substring of this string concept. The substring begins with the character at the specified index and extends to the end of this string.

            $str = "This is a test."
            print $str.substring(9)
            -- the result is --
            a test.
            

top
toLowerCase
Returns: String

Converts all of the characters in this string concept to lower case and returns the resulted string concept.

            $str = "ThIs iS a TeSt."
            print $str.toLowerCase
            -- the result is --
            this is a test.
            

top
toStringConcept
Returns: String

Returns a new string concept which is represents this concept.

            $str = "This is a test."
            print $str.toStringConcept
            -- the result is --
            This is a test.
            

top
toUpperCase
Returns: String

Converts all of the characters in this string concept to upper case and returns the resulted string concept.

            $str = "ThIs iS a TeSt."
            print $str.toUpperCase
            -- the result is --
            THIS IS A TEST.
            

top
trim
Returns: String

Removes white space from both ends of this string.

            $str = "  This is a test.   "
            print $str.trim
            -- the result is --
            This is a test.
            

top
wrap (Integer $value)
Parameters:
$value :Number of columns
Returns: String

Returns a new string concept representing this concept wrapped to the given column number and aligned to left by default.

            $str = "This is a test."
            print $str.wrap(5)
            -- the result is --
            This
            is a
            test.
            

top
wrap (Integer $value, String $align)
Parameters:
$value :Number of columns
$align :Alignment (ex. left, right, center)
Returns: String

Returns a new string concept representing this concept wrapped to the given column number and aligned as it is specified.

            $str = "This is a test string to verify the wrap method in this concept."
            print $str.wrap(10, "center")
            -- the result is --
            This is a
            test string
            to verify
             the wrap
            method in
               this
             concept.
            

top
wrap
Returns: String

Returns a new string concept representing this concept wrapped to 72 column and aligned to left by default.

            $str = "This is a test string to verify the wrap method in this concept. This must return a string concept with 72 column and aligned to left. Let's test it."
            print $str.wrap
            -- the result is --
            This is a test string to verify the wrap method in this concept. This
            must return a string concept with 72 column and aligned to left. Let's
            test it.
            

top