最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
从字符串中取一个字符作为数组元素
时间:2011-04-26 编辑:简简单单 来源:一聚教程网
从字符串中取一个字符作为数组元素
public class mainclass {
public static void main(string[] arg) {
string text = "to be or not to be"; // define a string
byte[] textarray = text.getbytes();
for(byte b: textarray){
system.out.println(b);
}
}
给数据增加值
class substringcons {
public static void main(string args[]) {
byte ascii[] = { 65, 66, 67, 68, 69, 70 };
string s1 = new string(ascii);
system.out.println(s1);
string s2 = new string(ascii, 2, 3);
system.out.println(s2);
}
}
转换成字节来一个十六进制字符串
import java.io.unsupportedencodingexception;
/**
* format validation
*
* this class encodes/decodes hexadecimal data
* @author jeffrey rodriguez
* @version $id: hexbin.java 125124 2005-01-14 00:23:54z kkrouse $
*/
public class main {
static private final int baselength = 255;
static private final int lookuplength = 16;
static private byte [] hexnumbertable = new byte[baselength];
static private byte [] lookuphexalphabet = new byte[lookuplength];
static {
for (int i = 0; i
}
for ( int i = '9'; i >= '0'; i--) {
hexnumbertable[i] = (byte) (i-'0');
}
for ( int i = 'f'; i>= 'a'; i--) {
hexnumbertable[i] = (byte) ( i-'a' + 10 );
}
for ( int i = 'f'; i>= 'a'; i--) {
hexnumbertable[i] = (byte) ( i-'a' + 10 );
}
for(int i = 0; i<10; i++ )
lookuphexalphabet[i] = (byte) ('0'+i );
for(int i = 10; i<=15; i++ )
lookuphexalphabet[i] = (byte) ('a'+i -10);
}
/**
* converts bytes to a hex string
*/
static public string bytestostring(byte[] binarydata)
{
if (binarydata == null)
return null;
return new string(encode(binarydata));
}
/**
* array of byte to encode
*
* @param binarydata
* @return return encode binary array
*/
static public byte[] encode(byte[] binarydata) {
if (binarydata == null)
return null;
int lengthdata = binarydata.length;
int lengthencode = lengthdata * 2;
byte[] encodeddata = new byte[lengthencode];
for( int i = 0; i
encodeddata[i*2+1] = lookuphexalphabet[ binarydata[i] & 0xf];
}
return encodeddata;
}
}
-
上一个: jsp 文件下载代码分享
-
下一个: jsp中变量常用方法
相关文章
- iOS 将数组里的元素逗号分隔成字符串 06-14
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24