⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 js.texi

📁 一个类似windows
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@example
var re = new RegExp ("d(b+)(d)", "ig");
var a = re.exec ("cdbBdbsbz");
a.toString ();
@result{} "dbBd,bB,d"
@end example
@c @end cartouche
@end defmethod

In the previous example, the result array @samp{a} has the following
items:

@table @code
@item dbBd
The substring that matched the regular expression.  This string can also
be retrieved as @samp{RegExp.lastMatch}.

@item bB
The matched substring for the first parenthesized subexpression
@samp{(b+)}.  This match can also be found as @samp{RegExp.$1}.

@item d
The matched substring for the second parentsized subexpression
@samp{(d)}.  This match can also be found as @samp{RegExp.$2}.
@end table

The option @samp{g} of the regular expression can be used to iterate
over multiple matches of the expression on at a time.  For example, the
following code fragment searches for the expression @samp{a(b*)} from
the string @samp{str}.  In the inial state -- when the expression is
create with the constructor -- the object's @samp{lastIndex} property is
set to 0.  When the expression is matched against the string, the
@samp{lastIndex} property is updated to point to the next index from
which the matching should be continued.  Therefore, the following
example iterates over all matches in the string @samp{str}.

@c @cartouche
@example
var re = new RegExp ("a(b*)", "g");
var str = "abbcdefabh";
while (a = re.exec (str))
  System.print ("Found ", a, ". Next match starts at ", re.lastIndex,
		    ".\n");
@print{} Found abb. Next match starts at 3.
@print{} Found ab. Next match starts at 9.
@end example
@c @end cartouche

The property @samp{@var{regexp}.lastIndex} can also be set explicitly to
start the matching from a pre-defined position.


@defmethod RegExp test ([string])
Test whether the regular expression matches for the string @var{string}.
If the argument @var{string} is omitted, the regular expression is
tested against the @code{RegExp.input} string.

@c @cartouche
@example
var re = new RegExp ("fo*bar");
re.test ("fbar");
@result{} true
re.test ("fooBar");
@result{} false

re = new RegExp ("fo*bar", "i");
re.test ("FOObAR");
@result{} true

RegExp.input = "#include <stdio.h>";
re = new RegExp ("^#");
re.test ();
@result{} true
@end example
@c @end cartouche
@end defmethod

@defcv {Static Property} RegExp {$1}
@defcvx {Static Property} RegExp {$2}
@defcvx {Static Property} RegExp {$3}
@defcvx {Static Property} RegExp {$4}
@defcvx {Static Property} RegExp {$5}
@defcvx {Static Property} RegExp {$6}
@defcvx {Static Property} RegExp {$7}
@defcvx {Static Property} RegExp {$8}
@defcvx {Static Property} RegExp {$9}
The matching substring for the @i{n}:th parenthesized subexpression.  If
the latest regular expression didn't have that many parenthesized
subexpressions, the property has value @samp{undefined}.
@end defcv

@defcv {Static Property} RegExp {$_}
@defcvx {Static Property} RegExp {input}
The string against which the expression was tested.  The @samp{input}
property is also used, if no string argument was given for the
@samp{test()} or @samp{exec()} methods.

@c @cartouche
@example
var str = file.readln ();
re.test (str);
RegExp.input;
@result{} @var{The string returned by the @samp{file.readln()} method.}
@end example
@c @end cartouche
@end defcv

@defcv {Static Property} RegExp lastMatch
The substring that matched the whole expression in the last regular
expression matching.
@end defcv

@defcv {Static Property} RegExp lastParen
The last parenthesized subexpression of the last regular expression
matching.
@end defcv

@defcv {Static Property} RegExp leftContext
The substring from the beginning of the input string to the beginning of
the matching substring of the last regular expression.

@c @cartouche
@example
var re = new RegExp ("foo");
var str = "garbage foo tail garbage";
re.exec (str);
RegExp.leftContext;
@result{} "garbage "
@end example
@c @end cartouche
@end defcv

@defcv {Static Property} RegExp multiline
@end defcv

@defcv {Static Property} RegExp rightContext
The substring from the end of the matching substring to the end the
input string.

@c @cartouche
@example
var re = new RegExp ("foo");
var str = "garbage foo tail garbage";
re.exec (str);
RegExp.rightContext;
@result{} " tail garbage"
@end example
@c @end cartouche
@end defcv

@defcv Property RegExp global
Flag that tells if the option @samp{g} was given for the constructor or
for the @code{compile} method.
@end defcv

@defcv Property RegExp ignoreCase
Flat that tells if the option @samp{i} was given for the construtor or
for the @code{compile} method.
@end defcv

@defcv Property RegExp lastIndex
The index from which the matching is continued with the global
(@samp{g}) expressions.
@end defcv

@defcv Property RegExp source
The source string from which the regular expression object was created.
@end defcv



@c ----------------------------------------------------------------------
@node String, System, RegExp, Native Objects
@subsection String

@table @strong
@item Standard
@value{ECMA}
@item Incompatibilities
@itemize @bullet
@item The constructor doesn't set the [[Prototype]] and [[Class]]
properties.
@end itemize
@end table

@deffn Constructor String (string)
Create a new string object and set its data to @var{string}.

@c @cartouche
@example
var str = new String ("Hello, world");
@result{} "Hello, world!"
@end example
@c @end cartouche
@end deffn


@defop {Static Method} String fromCharCode (code@dots{})
Create a new string object from the character codes @var{code}@dots{}.

@c @cartouche
@example
var str = String.fromCharCode (72, 101, 108, 108, 111, 33);
@result{} "Hello!"
@end example
@c @end cartouche
@end defop

@defop {Static Method} String pack (format, arg[, @dots{}])

@table @strong
@item Standard
@value{NGS}
@end table

Create a new string by packing values @var{arg}@dots{} to a string
according to the format string @var{format}.

The format is a sequence of characters that specify the type of values
as follows:

@table @code
@item C
an unsigned char value

@item n
a short in "network" (big-endian) order

@item N
a long in "network" (big-endian) order

@item d
a double-precision float in the native format
@end table
@end defop


@defmethod String append (string)

@table @strong
@item Standard
@value{NGS}
@end table

Append string @var{string} to the end of the string object.  The string
object must be a dynamic string, not a constant string literal.

@c @cartouche
@example
var str = new String ("");
str.append ("foo");
str.append ("-");
str.append ("bar");
@result{} "foo-bar"
@end example
@c @end cartouche
@end defmethod

@defmethod String charAt (position)
Create a new string that constains the character from position
@var{position} of the the string object.

@c @cartouche
@example
"foobar".charAt (3);
@result{} "b"
@end example
@c @end cartouche
@end defmethod

@defmethod String charCodeAt (position)
Return the code of the character at position @var{position} in the
string object.

@c @cartouche
@example
"foobar".charCodeAt (3);
@result{} 98
@end example
@c @end cartouche
@end defmethod

@defmethod String concat (@var{string}[, @dots{}])
Create a new string by appending the argument strings @var{string},
@dots{} to the end of the string object.

@c @cartouche
@example
"foo".concat ("bar");
@result{} "foobar"
@end example
@c @end cartouche
@end defmethod

@defmethod String crc32 ()

@table @strong
@item Standard
@value{NGS}
@end table

Count a 32-bit CRC of the string.

@c @cartouche
@example
var str = "Hello, world!";
System.print ("CRC32 of \"", str, "\" is ",
              str.crc32 ().toString (16), ".\n");
@print{} CRC32 of "Hello, world!" is e4928064.
@end example
@c @end cartouche
@end defmethod

@defmethod String indexOf (string[, start_index])
Return the index of the first substring of @var{string} within the
string object, or -1 if the string didn't contain the substring.  The
optional argument @var{start_index} can be used to specify the index
from which the searching is started.

@c @cartouche
@example
var str = "foobar foo bar foo";
str.indexOf ("foo");
@result{} 0
str.indexOf (" foo");
@result{} 6
str.indexOf ("foo", 1);
@result{} 7
str.indexOf ("Foo");
@result{} -1
@end example
@c @end cartouche
@end defmethod

@defmethod String lastIndexOf (string[, start_index])
Return the the index of the last substring of @var{string} within the
string object, or -1 if the string didn't contain the substring.  The
optional argument @var{start_index} can be used to specify the index
from which the searching is started.

@c @cartouche
@example
var str = "foobar foo bar foo";
str.lastIndexOf ("foo");
@result{} 15
str.lastIndexOf ("bar");
@result{} 11
str.lastIndexOf ("foo", 14);
@result{} 7
str.lastIndexOf ("Foo");
@result{} -1
@end example
@c @end cartouche
@end defmethod

@defmethod String match (regexp)
@end defmethod

@defmethod String replace (regexp, substitution)
@end defmethod

@defmethod String search (regexp)
@end defmethod

@defmethod String slice (start[, end])
@end defmethod

@defmethod String split (separtor[, limit])
@end defmethod

@defmethod String substr (start[, length])
@end defmethod

@defmethod String substring (start[, end])
@end defmethod

@defmethod String toLowerCase ()
Create a new string which contents is the data of the string object,
converted to the lower case.

@c @cartouche
@example
"FoObAr".toLowerCase ();
@result{} "foobar"
@end example
@c @end cartouche
@end defmethod

@defmethod String toUpperCase ()
Create a new string which contents is the data of the string object,
converted to the upper case.

@c @cartouche
@example
"FoObAr".toUpperCase ();
@result{} "FOOBAR"
@end example
@c @end cartouche
@end defmethod

@defmethod String unpack (format)

@table @strong
@item Standard
@value{NGS}
@end table

@end defmethod


@defcv Property String length
The length of the string.

@c @cartouche
@example
"foobar".length;
@result{} 6
var str = new String ("foo");
str.append ("bar");
str.length;
@result{} 6
@end example
@c @end cartouche
@end defcv


@node System, VM, String, Native Objects
@subsection System

@table @strong
@item Standard
@value{NGS}
@end table


@defop {Static Method} System chdir (directory)
Change the process' current working directory to @var{directory}.  The
function returns a boolean success status.
@end defop

@defop {Static Method} System error (any[, @dots{}])
Convert arguments @var{any}@dots{} to string and print the resulting
string to the standard error stream of the system.
@end defop

@defop {Static Method} System exit (code)
Terminate the program execution and return the value @var{code} to the
operating system as the return value of the running program.
Effectively the method performs C-code @samp{exit (@var{code})}.
@end defop

@defop {Static Method} System getcwd ()
Get the current working directory of the process.  The function returns
a strings presenting the directory or @code{false} if errors were
encountered.
@end defop

@defop {Static Method} System getenv (variable)
Return the value of the environment variable @var{variable}.  The method
returns the value as a string or @samp{undefined} if the variable was
not defined in the environment.
@end defop

@defop {Static Method} System popen (command, mode)
@end defop

@defop {Static Method} System print (any[, @dots{}])
Convert arguments @var{any}@dots{} to string and print the resulting
string to the standard output stream of the system.
@end defop

@defop {Static Method} System sleep (seconds)
Stop the interpreter for @var{seconds} seconds.
@end defop

@defop {Static Method} System strerror (errno)
Return a string that describes the system error code @var{errno}.
@end defop

@defop {Static Method} System system (command)
@end defop

@defop {Static Method} System usleep (micro_seconds)
Stop the interpreter for @var{micro_seconds} micro seconds.
@end defop

@defcv {Static Property} System bits
Return a value that describes the "bitness" of the underlying system.
Possible values might be @samp{16}, @samp{32}, @samp{64}, or even
@samp{128}.  Normally this is the size of a host system pointer in bits.
@end defcv

@defcv {Static Property} System canonicalHost
The canonical host name of the system where the interpreter was
compiled.

@example
System.stdout.writeln (System.canonicalHost);
@print{} powerpc-ibm-aix4.2.1.0
@end example
@end defcv

@defcv {Static Property} System canonicalHostCPU
The CPU part of the canonical host name.

@example
System.stdout.writeln (System.canonicalHostCPU);
@print{} powerpc
@end example
@end defcv

@defcv {Static Property} System canonicalHostVendor
The Vendor part of the canonical host name.

@example
System.stdout.writeln (System.canonicalHostVendor);
@print{} ibm
@end example
@end defcv

@defcv {Static Property} System canonicalHostOS
The OS part of the canonical host name.

@example
System.stdout.writeln (System.canonicalHostOS);
@print{} aix4.2.1.0
@end example
@end defcv

@defcv {Static Property} System errno
The system's error number.  The error number can be converted to a
string with the @code{strerror()} method of the System object.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -