함수 StringReverse()

(함수 reverseString()에서 넘어옴)
  다른 뜻에 대해서는 array_reverse 문서를 참조하십시오.

1 개요[ | ]

reverse
StrReverse
strrev
  • 문자열 뒤집기

2 Bash[ | ]

STR=$(echo "hello" | rev)
echo $STR

3 C[ | ]

#include <stdio.h>
#include <string.h>
int main() {
    char s[6] = "hello";
    int i, len, temp;
    len = strlen(s);
    for (i=0; i<len/2; i++) {
        temp = s[i];
        s[i] = s[len-i-1];
        s[len-i-1] = temp;
    }
    printf("%s\n", s); // olleh
}

4 C++[ | ]

#include <iostream>
#include <algorithm> 
using namespace std;
int main() {
    string s = "hello"; 
    reverse(s.begin(), s.end()); 
    cout << s; // olleh
}

5 C#[ | ]

using System;
class Program
{
    static string str_reverse(string str) {
        char[] arr = str.ToCharArray();
        Array.Reverse(arr);
        return new string(arr);
    }
    static void Main() {
        Console.Write(str_reverse("hello"));
    }
}

6 Excel[ | ]

Option Explicit
Public Function str_reverse(str As String)
    str_reverse = StrReverse(str)
End Function
=str_reverse("hello")

7 Java[ | ]

public class HelloWorld {
    public static void main(String [] args) {
        String s = "hello";
        String reversed = new StringBuilder(s).reverse().toString();
        System.out.println(reversed); // olleh
    }
}

8 JavaScript[ | ]

function reverse(s) {
  var o = '';
  for (var i = s.length - 1; i >= 0; i--) o += s[i];
  return o;
}
console.log( reverse('hello') ); // olleh
console.log( reverse('A가☆あ中!') ); // !中あ☆가A
function reverse(s){ return s.split("").reverse().join(""); }
console.log( reverse('hello') ); // olleh
console.log( reverse('A가☆あ中!') ); // !中あ☆가A
String.prototype.reverse = function(){return this.split("").reverse().join("");}
console.log( 'hello'.reverse() ); // olleh
console.log( 'A가☆あ中!'.reverse() ); // !中あ☆가A

9 Perl[ | ]

reverse "hello"              # returns "olleh"

10 PHP[ | ]

echo strrev("hello"); // olleh
echo strrev("A가☆あ中!"); // !��䂁㆘‰�A
echo strrev('Iñtërnâtiônàlizætiøn'); // n��it��zil��n��it��nr��t��I
function strrev8($str) {
    return iconv("UTF-16LE", "UTF-8", strrev(iconv("UTF-8", "UTF-16BE", $str)));
}
echo strrev8("A가☆あ中!") . "\n"; // !中あ☆가A
echo strrev8('Iñtërnâtiônàlizætiøn') . "\n"; // nøitæzilànôitânrëtñI

11 Python[ | ]

print( 'hello'[::-1] )
# olleh
def reverse(text):
    result = ""
    for i in range(0, len(text)):
        result = str(text[i]) + result
    return result

print( reverse('hello') )

12 R[ | ]

paste(rev(unlist(strsplit("hello",""))),collapse="")
## [1] "olleh"
paste(rev(unlist(strsplit("A가☆あ中!",""))),collapse="")
## [1] "!中あ☆가A"
s = "hello"
paste(substring(s,nchar(s):1,nchar(s):1),collapse="")
## [1] "olleh"
s = "A가☆あ中!"
paste(substring(s,nchar(s):1,nchar(s):1),collapse="")
## [1] "!中あ☆가A"
library(stringi)
stri_reverse("hello")
## [1] "olleh"
stri_reverse("A가☆あ中!")
## [1] "!中あ☆가A"

13 Ruby[ | ]

print "hello".reverse # olleh

14 Scheme[ | ]

(use-modules (srfi srfi-13))
(string-reverse "hello")     ; returns "olleh"

15 SQL[ | ]

15.1 MySQL[ | ]

SELECT REVERSE( "hello world" );
-- dlrow olleh

16 VB[ | ]

str = StrReverse("hello")

17 같이 보기[ | ]

18 참고[ | ]