• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trim funcation

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what would that error be?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can guess...
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well error is "The method trim(String) is undefined for the type AppUtil"
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok Well I got my mistake.. Thanks a lot for help
 
reply
    Bookmark Topic Watch Topic
  • New Topic