2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

paizaで使ったメソッド2

Last updated at Posted at 2018-09-30

##文字列の操作

var s = hello, world

charAt


s.charAt(0)             //最初の文字
"h"
s.charAt(s.length -1)   //最後の文字
"d"

substring,sline

var s = hello, world

s.substring(1,4)        //2番目から4番目の文字
"ell"
s.slice(1,4)                        //上と同じ
"ell"
s.slice(-3)                          //最後の3文字
"rld"
s.slice(-4)                          //最後の4文字
"orld"

####index

s.indexOf('l')          //最初のlの位置
2
s.indexOf('l',4)                //4文字目以降で最初のlの位置
9
s.lastIndexOf('l')            //最後のlの位置
9

####splitなど

s.split(',')
(2) ["hello", "world"]
s.replace('h','H')            //hをHに置き換える
"Hello,world"
s.toUpperCase()                  //小文字を大文字に置き換える
"HELLO,WORLD"
s.toLowerCase()                  //大文字を小文字に置き換える
"hello,world"
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?