new Buffer("Hello World").toString("base64"); /* yields SGVsbG8gV29ybGQNCg== */ new Buffer("SGVsbG8gV29ybGQNCg==").toString("ascii"); /* yields Hello World */
string weclome=""; byte[] data = new byte[1024]; //字符串转byte数组 data = Encoding.ASCII.GetBytes(welcome); //byte[]数组转ASCII字符串 weclome=Encoding.ASCII.GetString(data, 0, data.length)
nodejs的字符串操作需要引入querystring对象,querystring对象的方法有: 1:querystring.stringify(“对象”,“分隔符”,“分配符”),用来将一个json对象转为字符串: 如: var querystring = require('querystring'); var result = querystring.stringify({foo:'bar',cool:['xux', 'yys']},'*','$'); console.log(result)
关于byte[]数组转十六进制字符串: public static String getHexString(byte[] b) throws Exception { String result = ""; for (int i=0; i < b.length; i++) { result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 ); } return result; } public s
以前写了个java版的 现在写个nodejs 版的 var list = sort('CCAV');var noRepeat = {};for(var i in list){ noRepeat[list[i]] = list[i]; //去除重复}for(var i in noRepeat){ console.log(noRepeat[i]) //输出}function sort(str){ var arr = []; if(str.length == 1){ arr.push(str); re