我正试图从SSID获得信号强度。
我的输出是:ssid name + signal
示例:GIGABYTE 92%
但我只想输出:GYGABYTE 92
我想知道如何从输出中删除最后一个字符(%)。
请帮我解决。
这是我的代码:
ArrayList<String>ssids=new ArrayList<String>();
ArrayList<String>signals=new ArrayList<String>();
ProcessBuilder builder = new ProcessBuilder(
"cmd.exe", "/c", "netsh wlan show all");
builder.redirectErrorStream(true);
Process p = null;
try {
p = builder.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
try {
line = r.readLine();
if (line.contains("SSID")||line.contains("Signal")){
if(!line.contains("BSSID"))
if(line.contains("SSID")&&!line.contains("name")&&!line.contains("SSIDs"))
{
line=line.substring(8);
ssids.add(line);
}
if(line.contains("Signal"))
{
line=line.substring(30);
signals.add(line);
}
if(signals.size()==7)
{
break;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for (int i=1;i<ssids.size();i++)
{
System.out.println(ssids.get(i)+" "+signals.get(i));
}
}
}
答案 0 :(得分:0)
显然是:
line = line.substring(0,line.length() - 1);
会帮助你;)