Link to home
Start Free TrialLog in
Avatar of omarkkk
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:
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();
}

Open in new window


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(line);"  but I could not be able to do that..

any help :)

thanks :)
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of omarkkk
omarkkk

ASKER

Hi Doug,
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 :)
The split is not based on the name, it's based on the delimiter
Please show what the raw output is without the splitting
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This works with or without spaces
System.out.println(line.replaceAll("device","").trim());
Avatar of omarkkk

ASKER

I've requested that this question be deleted for the following reason:

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?
Avatar of omarkkk

ASKER

I've requested that this question be deleted for the following reason:

none
No reason you shouldn't!