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

18번째 줄: 18번째 줄:
     }
     }
}
}
</source>
==JavaScript==
{{참고|자바스크립트 ucfirst()}}
<source lang='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!
</source>
</source>



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

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!

5 PHP

<?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 }}