在字符串中取数字,运用的是subString方法。
public class Demo {
/**
* 需求: 即时视频传输 UDP协议 String 10000000
* video1.............
* video2.............
* video3.............
* video10.............
* video100............. 1440
* 取出video后的数字
* @author Whunf
*分析:用subString方式取出数字 ,数字所在的位置是第5位
*/
public static void main(String[] args) {
String video="video1223......";
System.out.println(getVideoIndex(video));
}
static int getVideoIndex(String pvideo){
int i = 8;
while (i-->0) {
String s = pvideo.substring(5, i+5);
try {
int index = Integer.parseInt(s);
return index;
} catch (Exception e) {
// TODO: handle exception
}
}
return 0;
}
}