This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing String to display each character individually?

 
Brian K Swingle
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How 'bout using the toCharArray() method of String, then just loop through the array and print the chars out?
HTH,
E
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian K Swingle
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic