Remove last char of string

Hi Guys
How can I remove the last char of a String ?

With [the substring method|http://java.sun.com/javase/6/docs/api/java/lang/String.html#substring(int,%20int)] .

Similar Messages

  • How to remove last char in a string by space

    I have to implement backspace application(remove a last char in a string , when we pressed a button).
    for ex: I enter the no
    1234
    instead of 1236
    So when i press a button on the JWindow... it should display
    123
    so that i can enter 6 now.
    I tried to display the string "123 " instead over "1234" but it is not working when the no background is specified. but works fine when a background color is specified.
    The string is displayed as
    Graphics2D g = (Graphics2D)window.getGraphics();
    AttributedString as = new AttributedString(string, map);
    g.drawString(as.getIterator(),x,y);
    In the map, the background is set to NO_BACKGROUND.
    Thanks and regards

    Deja vu. I saw this kind of post before, and I'm sure
    it was today.http://forum.java.sun.com/thread.jspa?threadID=588110&tstart=0
    Here it is.

  • Remove last char

    Ok i am trying to make just a simple calculator program for a class. I am trying to get the backspace button to work. How would i delete the last char in the string.

    use a substring, the last char. will be:
    myString.length
    that will give you the length and from that you know what the last char. is

  • How can I erase the last char of string

    I have a string tha is printing as following
    129.111.13.1.
    I want to erase the last "." can somebody helpme?
    Thanks

    You will have to create a new String. Then you can get the string length. Then you will need to to use a substring to get the positions you want.
    Something like this
    String Orginal = "129.111.13.1.";
    String new_orginal = null;
    int num;
    num = Original.length();
    new_orginal = Original.substring(0,num-1);
    I hope it helps

  • How to delete the last char in a String?

    i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?

    Try it in this way
    String MyString = "ABCDEF";
    MyString = MyString.substring(0,MyString.length()-1);

  • Deleting the last char of a string

    How can I Delete the last char of a string???
    example:
    asd@fdg@vvdfgfd@gdgdfgfd@gdfgdf@
    I want delete the last @!
    Tks in advance!

    hi,
    try this:
    lv_count = strlen(string).
    lv_count_last = lv-count - 1.
    replace string+lv_count_last(lv_count) in string by ' '.
    This should work.
    thnx,
    ags.
    Edited by: Agasti Kale on Jun 4, 2008 9:03 PM

  • Deleting last char in a string...

    I have a string that is created as follows: strBuffer += k.getKeyChar();(k is KeyPressed ...KeyEvent) How can I delete the last Char in the string strBuffer?

    Hi
    // simply substring
    if (strBuffer.length() > 1)
        strBuffer = strBuffer.substring(0, strBuffer.length()-1);
    // you may also use
    if (strBuffer.length() > 1)
        StringBuffer buffer = new StringBuffer(strBuffer).
                                   deleteCharAt(strBuffer.length()-1);
        strBuffer = buffer.toString();
    }I've not tested the above code myself & I've written the above code on the go after reading your query. The above code definitely work & help you.
    Regards,
    JPassion

  • Finding last char in the string

    Hi
    i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.
    thanks

    len = strlen(char).
    len = len - 1.
    if char+len(1) = '/'.
      *write ur code
    endif.
    chk this code
    REPORT ychatest.
    DATA : str(5) VALUE '123/',
           len TYPE i.
    len = STRLEN( str ).
    len = len - 1.
    IF str+len(1) = '/'.
      WRITE : '/ found'.
    ENDIF.
    <b>Reward points if helpful and close thrad if solved</b>
    Message was edited by: Chandrasekhar Jagarlamudi

  • Remove last 3 char ..

    Hi ,
         I need to remove last 3 char from my varible which is char 30.
    For example : WERKS = 1000 and .
    I need to remove last 3 char (and) from the above varibale .Kindly guide this
    Regards,
    VC

    Hi veerachamy,
    Just copy this code..it will work fine even if the field changes dynamically..
    I took w_char as 30 char..u can give ur field name there...
    data:
    w_char(30) type c value 'asdfghjklpoiu',
    w_tmp(30) type c,
    w_tmp1 type i.
    w_tmp1 = strlen( w_char ).
    w_tmp1 = w_tmp1 - 3.
    w_tmp = w_char+0(w_tmp1).
    write: w_tmp.
    Hope it resolves the issue...
    Regards
    Kiran

  • Read last char of a String

    I have the following code that functions like a basic RPN calculator:
    public class Main {
         * @param args the command line arguments
         static public ArrayList<Double> stack = new ArrayList<Double>();
         static double numberInput;
         static double answer;
         static String operation;
    //Prints Welcome screen, initialized checkforInput
         public static void main(String[] args) {
             System.out.println();
             System.out.println("Welcome to RPNCalc by theCoffeeShop()");
             checkForInput();
    //Checks for input, redirects to appropriate method
         public static void checkForInput() {
             Scanner reader = new Scanner(System.in);
          String input = reader.nextLine();
             if(isDouble(input) == true) {
                double number = Double.parseDouble( input );
                stack.add(0, number);
                repeat();
             } else {
                operation = input;
                operation();
    //Processes numeric operations
         public static void operation () {
             if(operation.equals("+")) {
                 answer = stack.get(1)+stack.get(0);
                 stack.add(0, answer);
                 System.out.println(answer);
                 repeat();
             } else if (operation.equals("-")) {
                 answer = stack.get(1)-stack.get(0);
                 stack.add(0, answer);
                 System.out.println(answer);
                 repeat();
             } else if (operation.equals("*")) {
                 answer = stack.get(1)*stack.get(0);
                 stack.add(0, answer);
                 System.out.println(answer);
                 repeat();
             } else if (operation.equals("/")) {
                 answer = stack.get(1)/stack.get(0);
                 stack.add(0, answer);
                 System.out.println(answer);
                 repeat();
             } else {
                 System.out.println("Incompatible operation");
                 repeat();
    //Called when ready to recheck for input
         public static void repeat() {
             checkForInput();
    //Checks if string is double
         public static boolean isDouble( String input )
            try
                Double.parseDouble( input );
                return true;
            catch(Exception e)
               return false;
    }To perform a basic operation (5+2), you would do the following
    5
    enter
    2
    enter
    (plus)
    enter
    Computer prints 7.
    I would like it to function like this:
    5
    enter
    2(plus)
    enter
    Computer prints 7.
    To do this, I have to be a be to split a string into 2 parts, the operation and the number. I think I could do this with a StringBuffer, but How to read the LAST char of a StringBuffer, instead of just a specific char? If there is a way to do it w/out a StringBuffer, I'm open to suggestions.

    Hint:
    The last character of a String (or StringBuilder or StringBuffer, etc.) is at the index (length_of_string - 1).
    Are you sure you're supposed to solve the problem this way? Usually homework assignments of this sort involve writing a whole parser.

  • Remove characters in a string

    wondering.. anyone knows how to remove characters in a string
    e.g.
    string: applepie
    after removing last 3 chars become "apple"
    thanks...

    That of course will only work for this example. Better solution is to use indexOf() to locate the position of the string you wish to remove. If the string you wish to remove is in the middle, then you will have to do a bit of extra work and concat two substrings.

  • Cutting last char in the XI

    hello experts
    I have a scenario RFC2WS and sending
      <?xml version="1.0" encoding="UTF-8" ?>
    - <rfc:ZRFC_POLICY_OR_INSURANCE xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
      <PASSWORD>kf001</PASSWORD>
      <USERNAME>kfirg001</USERNAME>
      </rfc:ZRFC_POLICY_OR_INSURANCE>
    but in the XI I am recieving
      <?xml version="1.0" encoding="UTF-8" ?>
    - <rfc:ZRFC_POLICY_OR_INSURANCE xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
      <PASSWORD>kf00</PASSWORD>
      <USERNAME>kfirg00</USERNAME>
      </rfc:ZRFC_POLICY_OR_INSURANCE>
    it is always cutting the last char in the username\password. in the RFC it is defined as a String.
    I couldnt find out why it is cutting the last char and help would be great.
    Thanks
    Kfir

    Hi,
    Is it possible for you to send it with Filed type as CHAR instead of String..
    In RFC source code you could handle this kind of conversion.
    Try with CHAR...instead of string.
    Thanks
    Swarup

  • How to remove the comma from string

    Hi,
    I Have string like below :
    String some1="123,44.22";
    I want to remove comma from string and final output should be 12244.22.
    public class getOut{
    public static void main(String args[]){
    String some1="123,44.22";
    getChars(int 0,some1.length(),char[] dst,0);
    can somebody in the forum give me idea how to remove comma from the String and
    have a string without comma.
    Thanks
    Jack

    int idx = oldString.indexOf(',');
    if(idx >= 0)   
          newString = oldString.substring(0, idx) + oldString.substring(idx + 1);or for jdk 1.4 and later
    str = str.replaceAll(",", "");

  • Last Char on a line

    I have a file that cat -e shows that the last char of each line is M-J.
    (" Non-ASCII characters (with the high bit set) are printed as `M-' (for meta) followed by the character for the low 7 bits.)
    Now, I can remove this with sed 's/.$//' but, what is char M-J, if I wanted to remove this with the actual char in sed (instead of using the wildcard ".$") ?

    Glad it worked. At first I was sure the M-J was somehow really ^M so I thought it was just a DOS/Windows CRLF file, especially since the 0xCA character didn't make any sense to me. Now I see (thanx to Niel!) that the character is the non-breaking space of the MacRoman character set. Still, not a common thing to see.
    BTW, this example uses a bash feature to insert the 0xCA character into the command line, so it probably won't work with other shells. If you put this line into a shell script, be sure to add
    "#!/bin/bash" at the top.
    Quoting special characters in the shell can be tricky and you don't show your entire command line, so I can't be sure if you had quoting around what you show. I showed the entire command, which worked for me, so I assume the difference is accounted for quoting that you didn't show.

  • Compare the last Char to the First Char in a Sting

    Hello, this should be easy but I'm having problems so here goes.
    I get the user to input a Stirng and I want it to compare the last Char to the first Char. I have writen this but StartWith can take a Char?
    public static void main(String[] args) {
            // TODO code application logic here
            String strA = new String();
            int length = 0;
            char lastLetter;
            System.out.println("Please input your first String: ");
                   strA = EasyIn.getString();
                 length = strA.length()-1;
                   lastLetter = strA.charAt(length);
           if( strA.endsWith(lastLetter))
                System.out.println("The first letter matches the last");
           else
                       System.out.println("They Don't match");
    }I have tried lastLetter.endsWith(strA) but that dosn't work some thing to do with it not taking Char
    From reading you can go strA.startWith("R") and that would look for R but you can't put a char in that would be a single letter.
    I also tried to lastletter to a string but then charAt wouldn't work.

    fixed it I used substring as its a string object any one recomend a better way let me know
    public static void main(String[] args) {
            // TODO code application logic here
            String strA = new String();
            int length = 0;
            String lastLetter;
            System.out.println("Please input your first String: ");
                   strA = EasyIn.getString();
                 length = strA.length()-1;
                   lastLetter = strA.substring(length);
           if( strA.startsWith(lastLetter))
                System.out.println("The first letter matches the last");
           else
                       System.out.println("They Don't match");
    }

Maybe you are looking for

  • Error while reassigning the FM from one FG to other.........

    Hi Gurus, While reassigning a Function Module from one Function Group to another I am getting the error:  Object components locked in different tasks... Please help. Abhi...

  • Steps for creation of track

    Hi Experts, Kindly tell me the steps for creating track in NWDI. Thanks in advance! Regards

  • Itunes does not download

    Iam trying to download itunes onto a Windows 8 laptop. I go to the site, fill in the details and click the download button. A screen comes up thanking me for downloading itunes but there is no download.  I am using ther Firefox browser an am running

  • Screen navigation between two components

    Hi, I have created 2 web dynpro component 1 and component 2. Component 1 has 1 view for ex: ABC and Component 2 has 2 views(XYZ1 and XYZ2, XYZ1 being the main view.) We have a requirement where we need to navigate from Component A iview ABC to compon

  • Compiling with makefiles

    I've found the make command in /Applications/Xcode.app/Contents/Developer/usr/bin so in the terminal window I type that long path to make a makefile. Then I get the error message. /Applications/Xcode.app/Contents/Developer/usr/bin/gcc -Wall   -c -o l