Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
String.replaceAt
String.charAt
String.elementAt
String.insertAt
String.subString
FUNCTION: String.replace
String.replace
(string, oldSubString, newSubString)
The
String.replace
function searches the given string, removes each occurrence of the designated old substring, replaces each occurrence with a designated new substring, and returns the modified string.
You can use the
String.replaceAt
function to replace a specified element in a string with a new substring (new element). The
String.subString
function can be used to return a substring out of a given string.
The mandatory
string
parameter can be any string containing one or more of any combination of characters and white spaces.
The mandatory
oldSubString
parameter can be any string containing one or more of any combination of characters and white spaces.
The mandatory
newSubString
parameter can be any string containing zero or more of any combination of characters and white spaces. This parameter can also be the empty string.
Code for ReplaceExample.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
replace example
</p>
<do type="accept">
<go href="ReplaceExample.wmls#findreplace()" />
</do>
</card>
<card id="card2">
<p>
string = $(oldstring)
<br />
old substring = $(oldsubstr)
<br />
new substring = $(newsubstr)
<br />
new string = $(newstring)
</p>
</card>
</wml>
Code for ReplaceExample.wmls
extern function findreplace()
{
var oldstr = Dialogs.prompt("Enter a string", "Hello wired world!");
var oldsub = Dialogs.prompt("Enter old substring", "wired");
var newsub = Dialogs.prompt("Enter new substring", "wireless");
var newstr =
String.replace(oldstr, oldsub, newsub)
;
WMLBrowser.setVar("oldstring", oldstr);
WMLBrowser.setVar("oldsubstr", oldsub);
WMLBrowser.setVar("newsubstr", newsub);
WMLBrowser.setVar("newstring", newstr);
WMLBrowser.go("ReplaceExample.wml#card2");
};
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information