Java version Description:
Java development, often encountered from GBK to Unicode code conversion; We often do the practice, there are about 2 kinds, one is: native2ascii; just save the file, edit the file every time, and then use the command to convert;
Another is: Eclipse plug-in properties Editor; Good usage, automatic editing; But the disadvantage is that eclipse must be used;
In order to develop convenient Ue+java, it is decided to configure properties transformation in UE and realize fast conversion (reversal);
the point :
Java Version conversion;
Because of the characteristics of Java itself, the conversion between Unicode and various encodings is easiest;
Usage: Java propertiestranslater "Convert string"
Java Propertiestranslater–reverse "Strings"
The configuration in the UE is as follows:
1. Add tool configuration to the toolbar:
2. The configuration tool is shown below, note that the parameter is%sel%, also can refer to UE document configuration;
3. Click Advanced to make the selected replacement
4. Configuration complete. The following can be in the UE, the selected text, and then press the corresponding tool shortcut keys;
You can convert the selected text to Unicode.
If you want to do a reverse conversion, just follow the above method, add the toolbar here, the command line parameter add
"-reverse" parameters can be;
/*********************************** Sample Code *********************************/
/**
*
* Propertiestranslater
*/
public class propertiestranslater{
public static void Main (string[] args) {
if (args ==null | | args[0]==null) {
SYSTEM.OUT.PRINTLN ("__ Error parameter Configuration __");
Return
}
if (args.length==2 && args[1]!=null && "-reverse". Equals (args[1)) {
String result = PROPERTIESTRANSLATER.UNICODE2GBK (args[0]);
System.out.print (result);
}else{
String result = Propertiestranslater.gbk2unicode (args[0]);
System.out.print (result);
}
}
/**
* Translate to Unicode
* @param str
* @return back to Unicode encoding
*/
public static string Gbk2unicode (String str) {
StringBuffer result = new StringBuffer ();
for (int i = 0; i < str.length (); i++) {
Char chr1 = (char) str.charat (i);
if (! Propertiestranslater.isneedconvert (CHR1)) {
Result.append (CHR1);
Continue
}
Result.append ("//u" + integer.tohexstring ((int) chr1));
}
return result.tostring ();
}
/**
* Unicode Transfer to Chinese
* @param str
* @return Chinese
*/
public static string UNICODE2GBK (String datastr) {
int index = 0;
StringBuffer buffer = new StringBuffer ();
while (Index<datastr.length ()) {
if (!) U ". Equals (Datastr.substring (index,index+2))) {
Buffer.append (Datastr.charat (index));
index++;
Continue
}
String charstr = "";
Charstr = datastr.substring (index+2,index+6);
Char letter = (char) integer.parseint (CHARSTR, 16);
Buffer.append (letter);
index+=6;
}
return buffer.tostring ();
}
public static Boolean Isneedconvert (char para) {
Return ((para& (0X00FF))!=para);
}
}
/*********************************** Sample Code *********************************/