-4

我有一个这样的字符串:

String programList = "List of programs: explorer.exe, conhost.exe, java.exe, something.exe..";

我想为自己的字符串创建每个具有“.exe”的单词,如下所示:

String program1 = "explorer.exe";
String program2 = "conhost.exe";
String program3 = "java.ex";
String program4 = "something.exe";
4

1 回答 1

1

使用类中的split()方法String,将适当的正则表达式作为参数传递:

String[] programs = programList.split("(,|:) ");

现在所有位置programs[1]programs[programs.length-1]将包含一个程序。提取它们很简单:

String program1 = programs[1];
String program2 = programs[2];
String program3 = programs[3];
String program4 = programs[4];
于 2013-06-15T16:49:53.870 回答