---
title: "how to reverse a nsstring"
author: "lovebirdegg"
date: "2010-04-16T10:04:03Z"
tags: ["C", "C#", "C++"]
categories: ["移动开发"]
slug: "how-to-reverse-a-nsstring"
draft: false
lastmod: "2010-04-16T10:07:06Z"
id: 645228
url: "https://lovebirdegg.iteye.com/blog/645228"
---

原文：<http://lovebirdegg.co.tv/2010/04/how-to-reverse-a-nsstring/>
some time you want to recerse a nsstring

for example：

"你好"to"好你"


i Searched the api but have no result，the method above can solute it

```java

NSString *content = [[nsstring alloc] initWithData:data encoding:NSUTF8StringEncoding];



int len = [content length];

// Auto released string



NSString * reversedStr = [[nsmutablestring alloc] init];



// Probably woefully inefficient...

while (len &gt; 0)

[reversedstr appendstring:

[nsstring stringwithformat:@&quot;%c&quot;, [content characteratindex:--len]]];

NSLog(reversedStr);


```