aspose file tools*
The moose likes Java in General and the fly likes splitting a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "splitting a string" Watch "splitting a string" New topic
Author

splitting a string

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,

Name/username Host Dyn Nat ACL Port Status
5102/5102 (Unspecified) D 0 Unmonitored

From the above i have to display the Name/username alone.I have tried the below code

it gives the following output

Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host
Name/username Host Dyn
Name/username Host Dyn Nat
Name/username Host Dyn Nat ACL
Name/username Host Dyn Nat ACL Port
Name/username Host Dyn Nat ACL Port
Name/username Host Dyn Nat ACL Port
Name/username Host Dyn Nat ACL Port
Name/username Host Dyn Nat ACL Port
Name/username Host Dyn Nat ACL Port Status
Name/username Host Dyn Nat ACL Port Status
Name/username Host Dyn Nat ACL Port Status
Name/username Host Dyn Nat ACL Port Status
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102
5102/5102 (Unspecified)
5102/5102 (Unspecified)
5102/5102 (Unspecified)

I think i have to check the string length and i have to use the separator to split the strings.but i dont know how to do in code.anybody explain me in code please.

Thanks.
Amod Mulay
Ranch Hand

Joined: Apr 06, 2006
Posts: 33
mystring = "firststring\secondstring some words"

First split it using array[] = mystring.split(" ");

then only that the first i.e names[] = array[0].split("\")
names[0] = "firststring"
names[1] = "secondstring"

a working example

public class StringSplit {
public static void main(String args[]) throws Exception{
new StringSplit().doit();
}

public void doit() {
// extra spaces
String s3 = "Real How To";
String [] temp = null;
temp = s3.split(" ");
dump(temp);
}

public void dump(String []s) {
System.out.println("------------");
for (int i = 0 ; i < s.length ; i++) {
System.out.println(s[i]);
}
System.out.println("------------");
}
}
/*
output :
------------
Real

How
To
------------
Amod Mulay
Ranch Hand

Joined: Apr 06, 2006
Posts: 33
mystring = "firststring\secondstring some words"

First split it using array[] = mystring.split(" ");

then only that the first i.e names[] = array[0].split("\")
names[0] = "firststring"
names[1] = "secondstring"

a working example

public class StringSplit {
public static void main(String args[]) throws Exception{
new StringSplit().doit();
}

public void doit() {
// extra spaces
String s3 = "Real How To";
String [] temp = null;
temp = s3.split(" ");
dump(temp);
}

public void dump(String []s) {
System.out.println("------------");
for (int i = 0 ; i < s.length ; i++) {
System.out.println(s[i]);
}
System.out.println("------------");
}
}
/*
output :
------------
Real

How
To
------------
Petrus Pelser
Ranch Hand

Joined: Feb 20, 2006
Posts: 132
Have a look at the Scanner class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: splitting a string
 
Similar Threads
update query issue
Using FTP in jsp
jcraft.jsch problem
Reading log files from various unix servers through Java program on windows
char cannot be dereferenced