Logo

Programming-Idioms

History of Idiom 41 > diff from v3 to v4

Edit summary for version 4 by :
↷

Version 3

2015-08-01, 16:59:43

Version 4

2015-08-18, 14:54:37

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.

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.

Imports
extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;
Code
let s = "lorém ipsüm dolör sit amor ❤ ";
let t = s.graphemes(true).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