wood burning stoves 2.0*
The moose likes JSP and the fly likes Trim Trailing Spaces from Field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Trim Trailing Spaces from Field" Watch "Trim Trailing Spaces from Field" New topic
Author

Trim Trailing Spaces from Field

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

I'm reading a database to get a Customer Name Char 40, Even though the Customer Name is 16 long , When I read it from the Database its 40 long. So I use the Code below to trim the traling spaces, I then Send it to an input Text box in my JSP which is a UPDATE form. If I then try to update this field , it wont let me unless I hit EOF first. Is there a way to fix this ? What am I missing ? Thanks

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Why aren't you:
  • using a VARACHAR DB type so that you dont have to wirry about trailing spaces to begin with?
  • or, using the builtin String trim method rather than inventing the wheel?
  • or, using the JSTL trim function rather than inventing the wheel?


  • I have no idea what you mean by "hitting EOF".


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Joe Brigs
    Ranch Hand

    Joined: Jun 06, 2011
    Posts: 60

    I will use the String Trim Function. I'm over 50 , I'm a Mainframe guy. So maybe EOF is a hold over but to be more clear on what I meant. If I do the keyboard combination of EOF ( end of file) which removes the invisible characters after the 1st 16 characters. Once I do the EOF I can key past the 16 characters etc. Also I work for a big shop, and were going against an existing os/390 DB2 database so changing a columns definition isn't that easy in my situation, Since there are a lot of backend programs that would need to be changed. Thanks for the help
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60785
        
      65

    Ah yes, dealing with legacy databases. Always a joy!

    In any case, if you want to trim in the Java code, using the String class' trim() method is the way to go. Trimming in the JSP itself should use the JSTL's trim() EL function.

    P.S. Over 50 here too.
     
    Consider Paul's rocket mass heater.
     
    subject: Trim Trailing Spaces from Field
     
    Similar Threads
    URLyBird: Reading the db-File
    trim function in Javascript
    Parsing
    NX: Random Access File, byte buffer
    removing a sequence from ANY string