JavaScript String Tools
Published on .
blabla
Play with the case
Top ↑"hello".isUpperCase()"HELLO".isUpperCase()"hELlo".isUpperCase()"HELLO".isLowerCase()"hello".isLowerCase()"hELlo".isLowerCase()"HelloWorld".lcfirst()"HELLO WORLD".lcfirst()"helloWorld".ucfirst()"hello world".ucfirst()"HELLO WORLD".ucwords()"hello world".ucwords()"HELLO WORLD".toLowerCase().ucwords()"hello".capitalize()"HELLO".capitalize()"123ABC".capitalize()"Hello".swapcase()"cYbEr_PuNk11".swapcase()
Center and justify
Top ↑"hello".ljust(4)"hello".ljust(20)"hello".ljust(20, "123")"hello".rjust(4)"hello".rjust(20)"hello".rjust(20, "123")"hello".center(4)"hello".center(20)"hello".center(20, "123")
" hello ".strip()" hello ".strip()"*hello*".strip("*")"*hello*\n".strip("*")" hello ".lstrip()" hello ".lstrip()"hello".lstrip("he")" hello ".rstrip()" hello ".rstrip()"hello".rstrip("lo")
Other
Top ↑"stressed".reverse()"x".repeat(5)"hello".repeat(5)"yellow moon".squeeze()" now is the".squeeze(" ")"putters shoot balls".squeeze("m-z")
Other
Top ↑"string\r\n".chop()"string\n\r".chop()"string\n".chop()"string".chop()"x".chop()"x".chop().chop()
"hello".chomp()"hello\n".chomp()"hello\r\n".chomp()"hello\n\r".chomp()"hello\r".chomp()"hello \n there".chomp()"hello".chomp("llo")
Type casting
Top ↑"12345".to_i()"99 red balloons".to_i()"0a".to_i()"0a".to_i(16)"hello".to_i()"1100101".to_i(2)"1100101".to_i(8)"1100101".to_i(10)"1100101".to_i(16)
"123.45e1".to_f()"45.67 degrees".to_f()"thx1138".to_f()