Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trim funcation

 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what would that error be?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can guess...
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well error is "The method trim(String) is undefined for the type AppUtil"
 
fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jiri Goddard
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok Well I got my mistake.. Thanks a lot for help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic