Author
Trim funcation
divya sharma
Ranch Hand
Joined: Jan 25, 2007
Posts: 87
posted Sep 11, 2007 14:12:00
0
Helli, i am trying to trim the user name. But when I call "trim" it shows me error. MyCode: import java.lang.String.*; import java.text.DecimalFormat ; import java.text.ParsePosition ; import java.text.SimpleDateFormat ; import java.util.ArrayList ; import java.util.Calendar ; import java.util.Date ; import java.util.GregorianCalendar ; import java.util.HashMap ; import java.util.List ; import java.util.Map ; import java.util.SimpleTimeZone ; import java.util.TimeZone ; import javax.servlet.http.HttpServletRequest ; import javax.servlet.http.HttpSession ; public final class AppUtil { // so that nobody can accidentally create an AppUtil object private AppUtil() { } /** * formatName - formats a name string given the individual name fields */ static public String formatName(String lastName, String firstName, String middleName, String suffix) { return AppUtil.trim(lastName) + ", " + AppUtil.trim(firstName) + " " + AppUtil.trim(middleName) + " " + AppUtil.trim(suffix); } } Thanks
Divya
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9950
what would that error be?
Never ascribe to malice that which can be adequately explained by stupidity.
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
I can guess...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
divya sharma
Ranch Hand
Joined: Jan 25, 2007
Posts: 87
posted Sep 11, 2007 15:00:00
0
Well error is "The method trim(String) is undefined for the type AppUtil"
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9950
So what is that telling you? You are calling the trim() method of the AppUtil class. That appears to be YOUR class. Have you defined a trim method in your class, that takes a string as a parameter?
Eric Duval
Greenhorn
Joined: Sep 12, 2007
Posts: 3
posted Sep 12, 2007 01:25:00
0
You need to use the trim method of String, not the trim method of AppUtil, which does not exist. So: return lastName.trim() + ", " firstName.trim() + " " + middleName.trim() + " " + suffix.trim();
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
Originally posted by Eric Duval: You need to use the trim method of String, not the trim method of AppUtil, which does not exist.
How would you know? The AppUtil class is presumably a class written by, or in use by, the original poster. Depending on what it does, the String.trim() may or may not be equivalent.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Jiri Goddard
Greenhorn
Joined: Aug 21, 2007
Posts: 21
Originally posted by Peter Chase: How would you know? The AppUtil class is presumably a class written by, or in use by, the original poster. Depending on what it does, the String.trim() may or may not be equivalent.
i would not sue him for this i have also my "wild guess" that the original poster wanted to use the String's trim() method.
http://dredwerkz.ic.cz
divya sharma
Ranch Hand
Joined: Jan 25, 2007
Posts: 87
posted Sep 12, 2007 07:58:00
0
Hi , Thanks a lot for your reply and you are correct that I want to use trim from String. Once again thanks for help !!! And Jiri I am not him I am her
Eric Duval
Greenhorn
Joined: Sep 12, 2007
Posts: 3
posted Sep 12, 2007 17:35:00
0
Oh, also you never need to import the java.lang.*; as far as I know... Such as: import java.lang.String.*; And you should consider just doing: import java.util.*; But that's just my opinion
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
Originally posted by Eric Duval: ...And you should consider just doing: import java.util.*;...
Well, that leaves a reader guessing exactly what's being used from java.util, and opens a door for name collisions.
divya sharma
Ranch Hand
Joined: Jan 25, 2007
Posts: 87
posted Sep 13, 2007 11:36:00
0
ok Well I got my mistake.. Thanks a lot for help
subject: Trim funcation