"함수 ucfirst()"의 두 판 사이의 차이

46번째 줄: 46번째 줄:
{{참고|PHP ucfirst()}}
{{참고|PHP ucfirst()}}
<source lang='php'>
<source lang='php'>
<?php
echo ucfirst( 'hello world!' );
echo ucfirst( 'hello world!' );
# Hello world!
# Hello world!
</source>
<source lang='php'>
echo ucfirst( 'HELLO WORLD!' );
echo ucfirst( 'HELLO WORLD!' );
# HELLO WORLD!
# HELLO WORLD!

2018년 10월 21일 (일) 16:41 판

1 개요

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

2 Java

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

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

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

5 PHP

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

6 Python

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

7 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}