Reverse a unicode string in your favourite language
Reverse a unicode string in your favourite language
Other urls found in this thread:
play.rust-lang.org
twitter.com
thanks but I'm sticking with SHIFT JIS
cshart
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
static string Reverse(string value)
{
static IEnumerable GetTextElements(string value)
{
var enumerator = StringInfo.GetTextElementEnumerator(value);
while (enumerator.MoveNext())
{
yield return enumerator.GetTextElement();
}
}
return string.Join("", GetTextElements(value).Reverse().ToArray());
}
There's already a thread for this.
fn reverse_string(input: &str) -> String {
input.chars().rev().collect()
}
play.rust-lang.org
imagine not having a decent STI
>inconsistent asterisk locations
stopped reading
def reverse(string):
string = string[::-1]
return string
use unicode_segmentation::UnicodeSegmentation;
fn reverse_string(string: &str) -> String {
let mut out = String::with_capacity(string.len());
for grapheme in string.graphemes(true).rev() {
out.push_str(grapheme);
}
out
}
package main
import "fmt"
func main() {
input := "Developers are a Diamond Dozen ™"
n := 0
rune := make([]rune, len(input))
for _, r := range input {
rune[n] = r
n++
}
rune = rune[0:n]
for i := 0; i < n/2; i++ {
rune[i], rune[n-1-i] = rune[n-1-i], rune[i]
}
output := string(rune)
fmt.Println(output)
}
in haskell this is just reverse
reverse2 = lambda x:x[::-1]
LMAOOOOOOOOO
import std;
void main()
{
"○□●■".retro.writeln;
}
import unicode
echo "I вoдкa".reversed()
irb(main):001:0> "分かる".reverse
=> "るか分"
String.reverse(str)
gnirts edocinu a
ReversedString = StrReverse(String)
public class Main {
public static String reverse(String string) {
char[] chars = string.toCharArray();
StringBuffer reversed = new StringBuffer();
for (int i = chars.length - 1; i >= 0 ; i--) {
reversed.append(chars[i]);
}
return reversed.toString();
}
public static void main(String[] args) {
System.out.println(reverse("god morning sirs!"));
}
}
Hired
This is a Unicode thread, not ASCII 2.0. Please finish your sophomore year and come back when you have it working on:
>Swedish flags
>White fistbump
>Poop emoji
>Composing accents
>This is a Unicode thread, not ASCII 2.0. Please finish your sophomore year and come back when you have it working on:
>>Swedish flags
>>White fistbump
>>Poop emoji
>>Composing accents
My solution works on all of those you retard. How about you learn what the fuck you're talking about before you pretend to be some kind of proctor?
Which one is yours?