함수 ucfirst()

1 개요[ | ]

함수 ucfirst()
  • "uppercase first"
  • 첫글자를 대문자로 바꾸는 함수

2 Java[ | ]

Java
Copy
public class MyClass {
    static String ucfirst(String str) {
        return  str.substring(0, 1).toUpperCase() + str.substring(1);
    }
    public static void main(String args[]) {
        System.out.println( ucfirst("hello world!") ); // Hello world!
        System.out.println( ucfirst("HELLO WORLD!") ); // HELLO WORLD!
    }
}

3 JavaScript[ | ]

JavaScript
Copy
function ucfirst(s) { return s.charAt(0).toUpperCase()+s.slice(1); }
console.log( ucfirst('hello world!') );
// Hello world!
console.log( ucfirst('HELLO WORLD!') );
// HELLO WORLD!

4 Perl[ | ]

Perl
Copy
print ucfirst('hello world!');
# Hello world!
Perl
Copy
print ucfirst('HELLO WORLD!');
# HELLO WORLD!

5 PHP[ | ]

PHP
Copy
echo ucfirst( 'hello world!' );
# Hello world!
PHP
Copy
echo ucfirst( 'HELLO WORLD!' );
# HELLO WORLD!

6 Python[ | ]

Python
Copy
s = 'hello world!'
print ( s[0].upper() + s[1:] )
# Hello world!
s = 'HELLO WORLD!'
print ( s[0].upper() + s[1:] )
# HELLO WORLD!

7 같이 보기[ | ]