reverse the order of characters in a string

后端 未结 13 1050
逝去的感伤
逝去的感伤 2020-12-04 15:03

In string \"12345\", out string \"54321\". Preferably without third party tools and regex.

13条回答
  •  青春惊慌失措
    2020-12-04 15:45

    Some simple methods of reversing a string

    echo '!!!esreveR si sihT' | grep -o . | tac | tr -d '\n' ; echo
    
    echo '!!!esreveR si sihT' | fold -w 1 | tac | tr -d '\n' ; echo
    

    Convert to hex values then reverse

    echo '!!!esreveR si sihT' | xxd -p | grep -o .. | tac | xxd -r -p ; echo
    
    echo '!!!esreveR si sihT' | xxd -p | fold -w 2 | tac | xxd -r -p ; echo
    

提交回复
热议问题