Skip navigation.

fox.tech

技術メモ

〔JSメモ〕文字列

// JavaScriptの文字列に関する覚え書き

var s="Hello, world";


*文字列の長さ:
document.write([B]s.length[/B]);


最後からn個目の文字:
last_char = [B]s.charAt(s.length - 1)[/B];  //最後の文字"d"
document.write(last_char);


先頭からm~n番目の文字(先頭文字を0とする):
sub = [B]s.substring(1,4)[/B]; //2~4番目("ell")
document.write(sub);

〔JSメモ〕エスケープシーケンス〔JSメモ〕変数とデータ型

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.