"함수 str repeat()"의 두 판 사이의 차이

(새 문서: category: string ;str_repeat ==PHP== category: PHP <source lang='PHP'> echo str_repeat("hello", 3); // hellohellohello </source> ==같이 보기== *for *str_pad *s...)
 
 
(사용자 2명의 중간 판 27개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[category: string]]
[[category: string]]
;str_repeat
{{DISPLAYTITLE:함수 str_repeat()}}
;함수 str_repeat()
 
==Go==
[[분류: Go]]
{{참고|Go strings.Repeat()}}
<syntaxhighlight lang='go' run>
package main
 
import (
"fmt"
"strings"
)
 
func main() {
fmt.Println(strings.Repeat("hello", 3)) // hellohellohello
}
</syntaxhighlight>
 
==Java==
[[분류: Java]]
{{참고|Java str_repeat()}}
<syntaxhighlight lang='Java' run>
public class MyClass {
    public static String str_repeat(String str, int times) {
        return new String(new char[times]).replace("\0", str);
    }
    public static void main(String args[]) {
        System.out.println( str_repeat("hello",3) ); // hellohellohello
    }
}
</syntaxhighlight>
<syntaxhighlight lang='Java' run>
public class MyClass {
    public static String str_repeat(String str, int times) {
        StringBuilder sb = new StringBuilder(str.length() * times);
        for (int i = 0; i < times; i++) sb.append(str);
        return sb.toString();
    }
    public static void main(String args[]) {
        System.out.println( str_repeat("hello",3) ); // hellohellohello
    }
}
</syntaxhighlight>
 
==JavaScript==
[[category: JavaScript]]
<syntaxhighlight lang='JavaScript' run>
var a = "hello";
var b = new Array(3+1).join(a);
console.log( b ); // hellohellohello
</syntaxhighlight>
<syntaxhighlight lang='JavaScript' run>
String.prototype.repeat=function(n){return new Array(n+1).join(this)}
console.log( "hello".repeat(3) ); // hellohellohello
</syntaxhighlight>
 
==Perl==
[[분류: Perl]]
<syntaxhighlight lang='Perl' run>
print "hello" x 3 # hellohellohello
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
{{참고|PHP str_repeat()}}
echo str_repeat("hello", 3);
<syntaxhighlight lang='PHP' run>
// hellohellohello
echo str_repeat("hello", 3); // hellohellohello
</source>
</syntaxhighlight>
 
==Python==
[[category: Python]]
<syntaxhighlight lang='Python' run>
print( "hello" * 3 ) # hellohellohello
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[for]]
* [[for]]
*[[str_pad]]
* [[함수 str_pad()]]
*[[substr_count]]
* [[함수 array_fill()]]
* [[함수 substr_count()]]

2023년 1월 19일 (목) 18:12 기준 최신판


함수 str_repeat()

1 Go[ | ]

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.Repeat("hello", 3)) // hellohellohello
}

2 Java[ | ]

public class MyClass {
    public static String str_repeat(String str, int times) {
        return new String(new char[times]).replace("\0", str);
    }
    public static void main(String args[]) {
        System.out.println( str_repeat("hello",3) ); // hellohellohello
    }
}
public class MyClass {
    public static String str_repeat(String str, int times) {
        StringBuilder sb = new StringBuilder(str.length() * times);
        for (int i = 0; i < times; i++) sb.append(str);
        return sb.toString();
    }
    public static void main(String args[]) {
        System.out.println( str_repeat("hello",3) ); // hellohellohello
    }
}

3 JavaScript[ | ]

var a = "hello";
var b = new Array(3+1).join(a);
console.log( b ); // hellohellohello
String.prototype.repeat=function(n){return new Array(n+1).join(this)}
console.log( "hello".repeat(3) ); // hellohellohello

4 Perl[ | ]

print "hello" x 3 # hellohellohello

5 PHP[ | ]

echo str_repeat("hello", 3); // hellohellohello

6 Python[ | ]

print( "hello" * 3 ) # hellohellohello

7 같이 보기[ | ]

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