---
title: "实现和 jdk\\bin\\native2ascii.exe 同样的功能"
author: "冽豹之姿"
date: "2011-03-12T13:14:19Z"
tags: []
categories: ["编程语言"]
slug: "jdk-bin-native2ascii-exe"
draft: false
lastmod: "2011-03-12T13:19:37Z"
id: 955987
url: "https://stdhj.iteye.com/blog/955987"
---

```java

	public static String convert(String str){
		String tmp;
		StringBuffer sb = new StringBuffer();
		char c;
		for (int i = 0; i < str.length(); i++) {
			c = str.charAt(i);
			if(c > 255){
				sb.append("\\u");
				tmp = Integer.toHexString(c);
				if(tmp.length() == 3){
					sb.append("0");
				}
				sb.append(tmp);
			}else{
				sb.append(c);
			}
		}
		return sb.toString();
	}

```