File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Parsing String to display each character individually? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Parsing String to display each character individually?" Watch "Parsing String to display each character individually?" New topic
Author

Parsing String to display each character individually?

Brian K Swingle
Ranch Hand

Joined: Jun 20, 2003
Posts: 39
Hello all,
This is my problem i have a string submited by the user which contains "OptiPlex GX1 800M+ " and a string from my database which contains the same thing "OptiPlex GX1 800M+ ". I know this cause i output them between Pipes to be sure. Like out.println("|" + StringName + "|"); . But when i use the .length property for each string the database string is 19 characters like it should be and the user input is 28 characters which is incorrect.
So i was wondering if some one had a short loop handy to parse out a string and out print each individual character. Any help is greatly appreciated.
Thanks,
Brian
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
How 'bout using the toCharArray() method of String, then just loop through the array and print the chars out?
HTH,
E


My theory of evolution is that Darwin was adopted. - Steven Wright
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Also, take a look at:
String test = test.trim();
This will get rid of the whitespace that you [probably] have at the end of the string.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Brian K Swingle
Ranch Hand

Joined: Jun 20, 2003
Posts: 39
Thanks for all your help. i used this to detyermine that there was 10 spaces on the end of the string.
char a[] = SystemModel.toCharArray();
int i = 0;
while (i != a.length)
{
out.println(a[i]+"|");
i++;
//out.println("" + i + "");
}
I tried to use th .trim before but i failed to use it correctly as i didn't reasign the trimed string to the string variable. Stupid me. but any way i solved my problem with your help.
Thanks very much,
Brian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing String to display each character individually?
 
Similar Threads
Vector problem
Having trouble with a simple character mapping program.
Special Characters
How to check whether the string contains only the specified characters?
ComboBox in jsp