Chapter 3 DynaScript Predefined Objects
Enables manipulation and formatting of strings as objects and objects as strings.
Standard: ECMAScript
To use a String method:
String.MethodName( parameter )
You can call String object as a function:
String( value );
or as a constructor:
myString = new String( value );
When called as a function, a type conversion is performed and a string is returned. A new String object is not created. When a String object is created through a constructor, a String object is returned.
This example creates a new String object:
<!--SCRIPT myString = new String( "hello" ); document.WriteLn( myString ); -->
String.charAt( position )
Returns the character in the string located at position. The position is 0 indexed.
Character.
This example displays the character e:
<!--SCRIPT myString = new String("hello"); document.WriteLn(myString.charAt(1)); -->
String.indexOf( substring [, position] )
Searches for substring within a string. You can optionally specify the position that the search is to begin. If not specified, the search begins at 0.
An integer indicating the start location of the substring. If the substring is not found, -1 is returned.
This example has a return of 3:
<!--SCRIPT myString = new String("hello world"); x = myString.indexOf("lo"); document.WriteLn(x); -->
String.lastIndexOf( substring [, position] )
Searches for the last occurrence of a substring within a script. The position that the search is to begin may be optionally specified. If not specified, the search will begin at 0.
An integer indicating the start location of the last substring found. If the substring is not found, -1 is returned.
This example has a return of 14:
<!--SCRIPT myString = new String( "hello world hello" ); x = myString.lastIndexOf( "ll" ); document.WriteLn( x ); -->
String.split( separatorString )
Separates a string at the separatorString and returns the resulting substrings as an Array object. The separatorString characters are not part of the returned substrings.
If an empty separator string is provided (" ") as the separator string, the string is split into an array of chars.
An Array object
This example splits a string each time the separator string 'split' is encountered:
<!--SCRIPT myString = new String( "This string will split each time the string 'split' is encountered" ); splitString = myString.split( "split" ); document.WriteLn( splitString ); -->
The output from this example looks similar to:
{ This string will , each time the string ', ' is encountered }
String.substring( start )
Returns a substring value that is extracted from the string object starting at the start value (numeric position) and continuing to the end of the string object.
String
This example returns "hello":
<!--SCRIPT myString = new String( "Hello world, hello" ); sampleString = myString.substring( 13 ); document.WriteLn( sampleString ); -->
String.substring( start, end )
Returns a substring value that is extracted from the string object starting at the start value and ending (but not including) the end value.
String
This example returns "world":
<!--SCRIPT myString = new String( "Hello world, hello" ); sampleString = myString.substring( 5, 11 ); document.WriteLn( sampleString ); -->
String.toLowerCase( )
Converts a string object to an entirely lower-case string.
String.
This example returns of "hello, world hello":
<!--SCRIPT myString = new String( "Hello world, hello" ); sampleString = myString.toLowerCase(); document.WriteLn( sampleString );--> -->
String.toString( )
Returns the string value of the object.
String
This example returns "Hello world, hello":
<!--SCRIPT myString = new String( "Hello world, hello" ); document.WriteLn( myString.toString() ); -->
String.toUpperCase( )
Converts a string object to upper case.
String
This example returns of "HELLO WORLD, HELLO":
<!--SCRIPT myString = new String( "Hello world, hello" ); sampleString = myString.toUpperCase(); document.WriteLn( sampleString ); -->
String.valueOf( )
Returns the string value.
String
This example returns "Hello world, hello":
<!--SCRIPT myString = new String( "Hello world, hello" ); document.WriteLn( myString.valueOf() ); -->
Copyright © 2001 Sybase, Inc. All rights reserved. |
![]() |