1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using System.Runtime.InteropServices;
5:
6: namespace String.Utilities {
7:
8: [Guid("80705AFF-708F-46f9-BA50-D69A96753A57")]
9: [ComVisible(true)]
10: [ClassInterface(ClassInterfaceType.None)]
11: public class Reverser : IReverser {
12:
13: // Types must have a public default constructor
14: // to be instantiated through COM. Managed public
15: // types are visible to COM, but without a public
16: // default constructor (a constructor without
17: // arguments), COM clients cannot create an
18: // instance of the type.
19: public Reverser() {
20: }
21:
22: #region IReverser Members
23:
24: public string Reverse(string str) {
25: // This method is from Mladen Prajdić's
26: // I want some Moore blog:
27: // http://weblogs.sqlteam.com/mladenp/
28: // archive/2006/03/19/9350.aspx
29:
30: char[] charArray = str.ToCharArray();
31: int len = str.Length - 1;
32:
33: for (int i = 0; i < len; i++, len--) {
34: charArray[i] ^= charArray[len];
35: charArray[len] ^= charArray[i];
36: charArray[i] ^= charArray[len];
37: }
38: return new string(charArray);
39: }
40:
41: public string BetterReverse(string str) {
42: // This method is from Mladen Prajdić's
43: // I want some Moore blog:
44: // http://weblogs.sqlteam.com/mladenp/
45: // archive/2006/03/19/9350.aspx
46:
47: char[] charArray = new char[x.Length];
48: int len = x.Length - 1;
49: for (int i = 0; i <= len; i++)
50: charArray[i] = x[len - i];
51: return new string(charArray);
52: }
53:
54: #endregion
55: }
56: }