Logo

Programming-Idioms

History of Idiom 41 > diff from v28 to v29

Edit summary for version 29 by sphinxc0re:
[Rust] because it works without the external crate
↷

Version 28

2016-11-13, 15:02:38

Version 29

2016-12-13, 20:53:44

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration
Imports
extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;
Imports
Code
let s = "lorém ipsüm dolör sit amor ❤ ";
let t = s.graphemes(true).rev().collect::<String>();
Code
let s = "lorém ipsüm dolör sit amor ❤ ";
let t = s.chars().rev().collect::<String>();
Comments bubble
Requires external crate `unicode-segmentation`: https://crates.io/crates/unicode-segmentation
Origin
http://unicode-rs.github.io/unicode-segmentation/unicode_segmentation/index.html
Demo URL
http://is.gd/jBNftC
Demo URL
https://is.gd/Jztpr6