| 情報学部 | 菅沼ホーム | 目次 | 索引 |
プログラム(下がそのソースコード)は,String オブジェクトのプロパティやメソッドの使用例である.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>String</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<META NAME=viewport CONTENT="width=device-width, initial-scale=1">
<LINK REL="stylesheet" TYPE="text/css" HREF="../../../master.css">
</HEAD>
<BODY CLASS="white">
<H1 STYLE="text-align: center">String オブジェクト</H1>
<SCRIPT TYPE="text/javascript">
let str = "例とする文書 Example Text";
document.writeln("<DL>");
document.writeln("<DT>元の文字: " + str);
document.writeln("<P>");
document.writeln("<DT>プロパティ");
document.writeln("<DD>文字列の長さ( length ): " + str.length);
document.writeln("<P>");
document.writeln("<DT>メソッド");
document.writeln("<DD>文字サイズ 7( fontsize ): " + str.fontsize(7));
document.writeln("<DD>少し大きく( big ): " + str.big());
document.writeln("<DD>少し小さく( small ): " + str.small());
document.writeln("<DD>太字( bold ): " + str.bold());
document.writeln("<DD>斜体( italics ): " + str.italics());
document.writeln("<DD>等幅文字( fixed ): " + str.fixed());
document.writeln("<DD>取消線( strike ): " + str.strike());
document.writeln("<DD>下付( sub ): " + str.sub());
document.writeln("<DD>上付( sup ): " + str.sup());
document.writeln("<DD>小文字( toLowerCase ): " + str.toLowerCase());
document.writeln("<DD>大文字( toUpperCase ): " + str.toUpperCase());
document.writeln("<DD>文字色(赤)( fontcolor ): " + str.fontcolor("red"));
document.writeln("<DD>3 文字目及び 7 文字目( charAt ): " + str.charAt(3) + " " + str.charAt(7));
document.writeln("<DD>7 文字目から 9 文字目を抜き出す( substring ): " + str.substring(7, 10));
document.writeln("<DD>7 文字目から 3 文字を抜き出す( substr ): " + str.substr(7, 3));
document.writeln("<DD>後ろから 12 文字目から 9 文字目を抜き出す( slice ): " + str.slice(-12, -9));
document.writeln("<DD>文字列 'Exa' を 'AAA' で置き換える( replace ): " + str.replace("Exa", "AAA"));
let part = str.split(" ");
document.write("<DD>文字列を空白で分割( split ): " + part[0]);
for (let i1 = 1; i1 < part.length; i1++)
document.write("/" + part[i1]);
document.write("\n");
document.writeln("<DD>文字列「x」の検索( indexOf ): " + str.indexOf("x", 0));
document.writeln("<DD>文字列「x」を後ろから検索( lastIndexOf ): " + str.lastIndexOf("x", 18));
document.writeln("<DD>文字列「Exa」の検索( match ): " + str.match(/Exa/i));
document.writeln("<DD>文字列「exa」の検索( search ): " + str.search(/exa/i));
document.writeln("<DD>リンクの設定( link ): " + "説明文へ".link("String.htm"));
document.writeln("<DD>文字コード( charCodeAt ): " + str.charCodeAt(0) + " " + str.charCodeAt(18));
document.writeln("<DD>文字コードを文字( fromCharCode ): " + String.fromCharCode(0x41, 0x42, 0x43));
document.writeln("<P>");
document.writeln("<DT>関連メソッド等");
let x = 20;
document.writeln("<DD>n 進数へ変換( toString ): 10 進数: " + x.toString(10) + ",2 進数: " + x.toString(2) + ",8 進数: " + x.toString(8) + ",16 進数: " + x.toString(16));
let now = new Date();
document.writeln("<DD>オブジェクト(日付)を文字列へ変換( toString ): " + now.toString());
document.writeln("<DD>オブジェクト(日付)内の値( valueOf ): " + now.valueOf());
document.writeln("</DL>");
</SCRIPT>
</BODY>
</HTML>
| 情報学部 | 菅沼ホーム | 目次 | 索引 |