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 :)
omarkkkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dpearsonCommented:
What went wrong with split?

This should work:

            String line = "192.168.56.101:5555      device" ;
            String[] words = line.split(" ") ;
            System.out.println("First word " + words[0]) ;

Doug
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
omarkkkAuthor Commented:
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 :)
0
CEHJCommented:
The split is not based on the name, it's based on the delimiter
Please show what the raw output is without the splitting
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

dpearsonCommented:
Yeah like CEHJ said, if you split on " " it will give you everything before and after a space.

So:

"I89613ba062a device"
"12312312.I89613ba062a                                    device"

should work fine.

However:
"I89613ba062a_________device"
"I89613ba062a.device"

wouldn't work (no spaces)

Another way to solve this is find where the word "device" appears in the line and return everything up to that:

             String line = "192.168.56.101:5555      device" ;
            int devicePos = line.indexOf("device") ;
            if (devicePos == -1)
                  devicePos = line.length() ;
            String rest = line.substring(0, devicePos).trim() ;
            System.out.println("All except device: " + rest) ;

Doug
0
awking00Information Technology SpecialistCommented:
This works with or without spaces
System.out.println(line.replaceAll("device","").trim());
0
omarkkkAuthor Commented:
I've requested that this question be deleted for the following reason:

not good question!
0
CEHJCommented:
omarkkk, please select the comments that have been given. People here have tried to help you
0
awking00Information Technology SpecialistCommented:
omarkkk,
Did you try my suggestion? If you did and it didn't work, can you provide an example where it failed?
0
omarkkkAuthor Commented:
I've requested that this question be deleted for the following reason:

none
0
awking00Information Technology SpecialistCommented:
No reason you shouldn't!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.