Web tier: servlets, JSP, Web frameworks: How can we trim in Jsp.?

  1. How can we trim in Jsp.? (3 messages)

    hi everybody,

      i am new to java and jsp I have a doubt. In Vb i am using trim for removing white spaces. and also i am using to trim from left as LEFT(string, number) and for trimming from Right as RIGHT(string, number). but in java or jsp how can we do . I tried but i could not get the result.below one is the code i tried.

    String strsql=" select * from emp where" ;
     strsql = Trim(strsql)
          If (Right(strsql, 3) == "and" )
             strsql = Left(strsql, length(strsql) - 3)
          If (Right(strsql, 5) == "where" )
            strsql = Left(strsql, length(strsql) - 5)

    Note: I used these in predicting as.....
    length -- to know the length of the string
    Trim -- to remove the white spaces in the string
    Right(strsql, 3) -- to check the String from rightside upto 3 characters.
    Left(strsql, length(strsql) - 3) -- to remove 3 characters from left side of the string.
     pls do me correct in this regard and give me one example so that i can understand well.



    Threaded Messages (3)

  2. How can we trim in Jsp.?[ Go to top ]

    Try this:

    String strsql=" select * from emp where";
    strsql = strsql.trim();

    if (strsql.endsWith("and")) {
      strsql = strsql.substring(0, strsql.lastIndexOf("and"));

    if (strsql.endsWith("where")) {
      strsql = strsql.substring(0, strsql.lastIndexOf("where"));


  3. How can we trim in Jsp.?[ Go to top ]

    hi andy,

      thanks for ur cooperation... it is working.


  4. How can we trim in Jsp.?[ Go to top ]

    try this :


    it returns a copy of the invoking string from which any leading and trailing whitespace has been removed.