omarkkk
asked on
taking part of the string
Hi,
I have an output of the "adb devices" command, it's working and showing the output,
what I need is to only print the device name..
here is the code:
and here is the output:
List of devices attached
192.168.56.101:5555 device
What I want is to print only the device name which is "192.168.56.101:5555"
I tried using split before this line"System.out.println(li ne);" but I could not be able to do that..
any help :)
thanks :)
I have an output of the "adb devices" command, it's working and showing the output,
what I need is to only print the device name..
here is the code:
public void newExec() throws IOException, InterruptedException, BadLocationException{
String adbPath = "/Volumes/development/android-sdk-macosx/tools/adb";
String cmd = adbPath+" "+"devices";
Process p;
p=Runtime.getRuntime().exec(cmd);
p.waitFor();
String line;
BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = err.readLine()) != null){
System.out.println(line);
}
err.close();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line=input.readLine())!=null){
//printing in the console
System.out.println(line);
//copy to the text area
textArea.append("\n"+line);
}
input.close();
}
and here is the output:
List of devices attached
192.168.56.101:5555 device
What I want is to print only the device name which is "192.168.56.101:5555"
I tried using split before this line"System.out.println(li
any help :)
thanks :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The split is not based on the name, it's based on the delimiter
Please show what the raw output is without the splitting
Please show what the raw output is without the splitting
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This works with or without spaces
System.out.println(line.re placeAll(" device","" ).trim());
System.out.println(line.re
ASKER
I've requested that this question be deleted for the following reason:
not good question!
not good question!
omarkkk, please select the comments that have been given. People here have tried to help you
omarkkk,
Did you try my suggestion? If you did and it didn't work, can you provide an example where it failed?
Did you try my suggestion? If you did and it didn't work, can you provide an example where it failed?
ASKER
I've requested that this question be deleted for the following reason:
none
none
No reason you shouldn't!
ASKER
The problem is that the device name is not static
sometimes it's this "192.168.56.101:5555" but some times when using another device "I89613ba062a",
what i need is to split the device name even if i change it!
and only device name without the word device, so if possible only this part "192.168.56.101:5555"
so it's like splitting from the second line, and only taking devices name without device word!
thanks :)