spacer
Yehuda Shiran July 1, 2000
WMLScript's String Library
Tips: July 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

The WMLScript String library includes a set of string functions that are part of the JavaScript language. A string in WMLScript is an array of characters. The first character has an index of 0. A string may be divided into elements by a special user-defined separator. A white-space character is either TAB (Horizontal Tabulation), VT (Vertical Tabulation), FF (Form Feed), SP (Space), LF (Line Feed), or CR (Carriage Return). The following functions are part of the String library: length(), isEmpty(), charAt(), subString(), find(), replace(), elements(), elementAt(), removeAt(), replaceAt(), insertAt(), squeeze(), trim(), compare(), toString(), and format().

The concept of elements is unique to WMLScript. You can split a string to its elements (separated by a user-given character), replace elements with other elements, remove them, insert new ones, etc. Go to Column 63, The String Library, to see a detailed definition of each function, including examples. Here is the definition of the elementAt() function:

elementAt()

This function first separates the given string into elements according to the specified separator, and then returns the element with the given index. If the index is negative, the first element is returned. If it is out of range, the last element is returned. If the string is empty, an empty string is returned. If the separator is empty, invalid is returned. If the index is floating-point, Float.int() is used to convert it to an integer. No case folding is done.

SyntaxelementAt(string, index, separator)
Parametersstring = String, index = Integer, separator = String
ReturnsString or invalid
Examples:var a = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", 1, " "); // a = "JavaScript"
var b = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", 0, "J"); // b = "Doc "
var c = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", -5, " "); // c = "Doc"
var d = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", 12, " "); // d = "tips"
var e = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", 1, ""); // e = invalid
var f = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", "kuku", " "); // f = invalid
var g = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", 0, J); // g = "Doc "
var h = String.elementAt("Doc JavaScript is a leading source for JavaScript tips", 0, "j"); // h = ""


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2 · Create Multilingual Web Sites with Windows Unicode Fonts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MySql View Technique for Grouping Crosstab Column Data · Why You Need a Mobile Web Site · Tame Web Marketing with Social Media Management