}:r: Start reader loop. !~>& Push a character to the "stack". <:a:=- Stop reading on newline.^:r:@> Rotate the newline to the end and enqueue a sentinel 0.{~ Dequeue and rotate the first character into place.}:p: ${~ Print the current character until it's 0.^:p:#:r: Read again.

C# does not have a built-in Reverse method for strings, which are immutable. One way to implement this is to convert the string to an array of characters, reverse that, and return a new string from the reversed array:

As of .Net 3.5 you can call LINQ's Reverse extension method on a string, since String implements the IEnumerable<char> interface. Because of this, the return type of Reverse is IEnumerable<char>. Fortunately, LINQ also provides the ToArray extension method, which can be used in conjunction with one of the constructors belonging to the String class which accepts an array of chars:

Handling combining characters present a trickier task. We need to protect the relative ordering of the combining character and the character to its left. Thus, before reversing, the characters need to be grouped.

(defn combining? [c](let[type (Character/getType c)];; currently hardcoded to the types taken from the sample string(or(= type 6)(= type 7))))

Since Dart strings are sequences of UTF-16 code units, it would not be sufficient to simply reverse the characters in strings, as this would not work with UTF-16 surrogate pairs (pairs of UTF-16 code units that represent single characters outside the Unicode BMP). However, Dart provides a method to convert strings to sequences of unicode code points (called "runes" in Dart), and these sequences can easily be reversed and used to create new strings, so a string reversal function can be written with a single line of Dart code:

Erlang also supports binary strings, which uses its binary format. There is no standard function to reverse a binary sequence, but the following one does the job well enough. It works by changing the endianness (from little to big or the opposite) of the whole sequence, effectively reversing the string.

DYNASM RevStr(BYVAL s AS STRING) AS STRING// get length of string// divide by two// setup pointers to head and tail// iterate from 1 to (length \ 2)// swap head with tail// increment head pointer// decrement tail pointer

ENTER0,0// = PUSHEBP:MOVEBP,ESPPUSHEBX// by Windows convention EBX,EDI,ESI must be saved before modification

MOVEAX, s // get string pointerMOVECX,EAX// duplicate it

.WHILE BYTE PTR [ECX] <> 0

INCECX// propagate to tail

.WEND

MOVEDX,ECX// duplicate tail pointerDECEDX// set it to last byte before trailing zero

Using the Forth-2012 Xchars wordset to handle multi-byte characters[edit]

Characters accessed with C@ C! are usually bytes and can therefore only represent characters in 8-bit encodings (e.g., Latin-1). Forth-2012 added the Xchars wordset for dealing with multi-byte encodings such as UTF-8; actually these words are not needed much, because the magic of UTF-8 means that most byte-oriented code works as intended, but the present task is one of the few examples where that is not good enough.

The xchars wordset offers several ways to skin this cat; this is just one way to do it, not necessarily the best one. Because the xchars wordset currently does not support recognizing combining characters, this code does not get extra credit.

Functions below assume UTF-8 encoding. (The task mentions Unicode but does not specify an encoding.) Strings in Go are not restricted to be UTF-8, but Go has good support for it and works with UTF-8 most natually. As shown below, certain string conversions work in UTF-8 and the range clause over a string works in UTF-8. Go also has a Unicode package in the standard library that makes easy work of recognizing combining characters for this task.

Then we need to box groups of letters and combining characters, reverse, and unbox. The boxing function can be carried out easily with dyad cut, which uses the indices of the ones on the right as the starting points for groups of characters. For clarity, its inverse will be defined as raze, which simply runs together the items inside boxes of its argument.

split=. (<;.1~ -.@iscombining) :. ;

After this, the solution is just to reverse under the split transformation. This also takes place under J code to convert from Unicode to integers.

jq's explode/implode filters are based on codepoints, and therefore "reverse_string" as defined here will reverse the sequence of codepoints.
The topic of Unicode combining characters is a large one that is not touched on here.

The reverse function reverses codepoints (because this is the right behavior for the main application of string reversal: reversed string processing by external C libraries). However, starting in Julia 0.4, you can also reverse the graphemes if you want (i.e. to reverse "visual order" including combining characters etc.) by:

This image is a VI Snippet, an executable image of LabVIEW code. The LabVIEW version is shown on the top-right hand corner. You can download it, then drag-and-drop it onto the LabVIEW block diagram from a file browser, and it will appear as runnable, editable code.

More verbose than the string->reverse method, but this example illustrates different techniques to achieve the same result:
using string->values to iterate over a string in order, inserting at position 1, and joining the resulting array as a string.

A string is stored as a zero-terminated array of character codes. To reverse it, we first scan forwards until we find the end; we then move backwards again, copying each code into a block of memory we have reserved for the purpose; and finally, when we have got back to the beginning, we append a terminal zero to the new string we have created. We can then call PUTS to print it.

A built-in function, "fliplr(string)" handles reversing a string of ASCII characters. Unicode is a whole other beast, if you need this functionality test to see if "fliplr()" properly handles the unicode characters you use. If it doesn't then you will need to code a function that is specific to your application.

Sample Usage:

>> fliplr(['She told me that she spoke English and I said great. '...'Grabbed her hand out the club and I said let''s skate.'])

This is heavily based off of the Copy String solution. Only a few lines are changed. In the Copy String solution, the pointer at the source string starts at 0th then keeps adding until the loaded byte isn't 0. This instead when copying the string starts at the last index, then decrements the source pointer a number of times equal to the determined string length.

# First, it gets the length of the original string# Then, it allocates memory from the copy# Then it copies the pointer to the original string, and adds the strlen# subtract 1, then that new pointer is at the last char.# while(strlen)# copy char# decrement strlen# decrement source pointer# increment target pointer

alloc_mem: li $v0,9 #alloc memory, $a0 is arg for how many bytes to allocate #result is stored in $v0 syscall la $t0,($v0) #$v0 is static, $t0 is the moving ptr la $v1,($t1) #get a copy we can increment

The following only works on implementations which implement Level 1 of standard Pascal (many popular compilers don't).

Standard Pascal doesn't have a separate string type, but uses arrays of char for strings. Note that Standard Pascal doesn't allow a return type of char array, therefore the destination array is passed through a var parameter (which is more efficient anyway).

{ the result array must be at least as large as the original array }procedure reverse(s:array[min ..max:integer]ofchar,var result:array[min1 ..max1:integer]ofchar);var i, len:integer;begin len := max-min+1;for i :=0to len-1do result[min1 + len-1- i]:= s[min + i]end;

However that would go horribly wrong on utf8 strings, even without combining characters, so... this seems ok on "as\u203Ddf\u0305", as long as it is displayed in a message box rather than a Windows Console (even with chcp 65001 and Lucida Console, the characters do not combine).

function unicode_reverse(string utf8)sequence utf32 = utf8_to_utf32(utf8)integer ch -- the assumption is made that <char><comb1><comb2> -- and <char><comb2><comb1> etc would work the same. for i=1 to length(utf32) do ch = utf32[i] if (ch>=0x300 and ch<=0x36f) or (ch>=0x1dc0 and ch<=0x1dff) or (ch>=0x20d0 and ch<=0x20ff) or (ch>=0xfe20 and ch<=0xfe2f) then utf32[i] = utf32[i-1] utf32[i-1] = ch end if end for utf32 = reverse(utf32) utf8 = utf32_to_utf8(utf32) return utf8end function

revstring("asdf")revstring("m\u00f8\u00f8se")Encoding("m\u00f8\u00f8se") # just to check if on your system it's something # different!

Output:

[1] "fdsa"
[1] "esøøm"
[1] "UTF-8"

R can encode strings in Latin1 and UTF-8 (the default may depend on the locale); the Encoding(string) can be used to know if the string is encoded in Latin1 or UTF-8; the encoding can be forced (Encoding(x) <- "latin1"), or we can use iconv to properly translate between encodings whenever possible.

Unicode-aware, method 2: I can't guarantee it get all the cases, but it does work with combining characters as well as supplementary characters. I did not bother to preserve the order of newline characters, and I didn't even consider directionality beyond just ruling it out.

Public Function RReverse(aString As String) As String'returns the reversed string'do it recursively: cut the string in two, reverse these fragments and put them back together in reverse orderDim L As Integer 'length of stringDim M As Integer 'cut point

This only handles ASCII characters. It works by converting a string to an array of char; dropping the last character (which is the null byte); reversing the order of the characters; then converting back to a string.