java怎么按字段长度截取字符串
发布网友
发布时间:2022-05-29 05:45
我来回答
共4个回答
热心网友
时间:2023-10-08 20:14
String info="F1ASC9DSZSRSY9B9M9K9L9Q9G9S9NSV9U2W3TSES*9";
for(int i=0;i<info.length();i++)
{
String tmp=info.substring(i,i+1);
int ascll=tmp.charAt(1);
// 是否为数字
if(ascll<48 || ascll>57)
System.out.print(tmp.substring(0)+"=0");
else
System.out.print(tmp.substring(0)+"="+tmp.substring(1));
}
热心网友
时间:2023-10-08 20:15
public class StringTest {
static String string = "F1ASC9DSZSRSY9B9M9K9L9Q9G9S9NSV9U2W3TSES*9";
public static void main(String[] args)
{
for(int i = 0;i<string.length()-1;i++)
{
char c = string.charAt(i);
if(Character.isLetter(c))
{
String subString = new String(string.substring(i,i+2));
output(subString);
}
else
{
continue;
}
}
}
public static void output(String subString)
{
System.out.print(subString.charAt(0)+" = "+(Character.isDigit(subString.charAt(subString.length()-1))?subString.charAt(1):"0")+" ");
}
}
热心网友
时间:2023-10-08 20:15
public void method4(String tmp){
int len = tmp.length();
if(len < 2){ System.out.println("字符串太短");}
for(int i = 0 ; i<len/2 ; i++){
String subTmp = tmp.substring(i*2, i*2+2);
String char1 = subTmp.substring(0, 1);
char char2 = subTmp.substring(1).charAt(0);
if(char2>57 || char2<48){char2=48;}
System.out.println(char1+":"+char2);
}
}
public static void main(String[] args) {
String tmp = "F1ASC9DSZSRSY9B9M9K9L9Q9G9S9NSV9U2W3TSES*9";
BaiDu prime = new BaiDu(100);
prime.method4(tmp);
}
热心网友
时间:2023-10-08 20:16
牛,都是牛人