aspose file tools*
The moose likes Beginning Java and the fly likes Trim funcation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trim funcation" Watch "Trim funcation" New topic
Author

Trim funcation

divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
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: 11499
    
  16

what would that error be?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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
Well error is "The method trim(String) is undefined for the type AppUtil"
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

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
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.
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
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
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
ok Well I got my mistake.. Thanks a lot for help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trim funcation