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

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 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)] .

  • 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

  • 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.

  • Best way to remove last line-feed in text file

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)
    According to my experiments, you have removed all line terminators from the file, and replaced those between lines with a space.
    That is to say, you have turned a multi-line file into one long line with no line terminator.
    If that is what you want, and your files are not very big, then your echo statement might be all you need.
    If you need to deal with larger files, you could try using the 'tr' command, and something like
    tr '
    ' ' ' <file.txt >newfile.txt
    The only problem with this is, it will most likely give you a trailing space, as the last newline is going to be converted to a space. If that is not acceptable, then something else will have to be arranged.
    However, if you really want to maintain a multi-line file, but remove just the very last line terminator, that gets a bit more complicated. This might work for you:
    perl -ne '
    chomp;
    print "
    " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    You can use cat -e to see which lines have newlines, and you should see that the last line does not have a newline, but all the others still do.
    I guess if you really did mean to remove all newline characters and replace them with a space, except for the last line, then a modification of the above perl script would do that:
    perl -ne '
    chomp;
    print " " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    Am I even close to understanding what you are asking for?

  • 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);

  • 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 Char.from one Operating Concern

    Hi Guys,
    How to remove the Char. from one Operating Concern.
    I have created one Char. (WWDOC) and moved to Operating Concern (OOCC). Operating Concern is in red status.
    Now, i want to remove that new assigned Char. (WWDOC)from the operating concern (OOCC). I did't find any option in the menu also.
    Appreciate your help.....
    T&R
    VVR

    Hi Sasi,
    Iam not able to push back that char. from my operating concern. In help it is given you have to delete the data contents in the table before pushing back. Please let me know if any other option available.
    Thanks for your reply.
    VVR

  • 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

  • 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");
    }

  • 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 selection for parameters

    Hello expert,
    I have a webi report with multiple parameter inherited from store procedure on which universe is built up. how can I remove last select variant for all parameters ? I mean for every running, I want to select parameters from scratch. but currently in my report, parameters display last selection.
    Many Thanks,

    Hello,
    I believe if you go into the universe and right click on the stored procedure, it should give you an edit option. Then you should be able to select the parameter and change it to "Prompt for a value" or something like that. There are probably some other posts regarding how to do this. I am not sure I have it all correct since I don't have BO up right now, but pretty sure I have done it before.
    Thanks

  • Remove Last part

    i have this data
    ELECT  [item_id]  ,[f2] from [Regions]
    1. ُEgypt
    1.1. Cairo
    1.1.21. New Cairo
    i want to remove last part 
    like in Egypt remove 1.
    and on Cairo remove  last 1.
    and on New Cairo last 21.

    Try:
    DECLARE @City TABLE ( CityName varchar(100));
    INSERT @City VALUES
    ('1. Egypt'),
    ('1.1. Cairo'),
    ('1.1.21. New Cairo'),
    ('1.1.21.5. Alexandria')
    -- SELECT STUFF('abcdef', 2, 3, 'ijklmn');
    SELECT
    CityName, RenumberedCityName=
    LTRIM(STUFF(REVERSE(SUBSTRING(SUBSTRING(REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)+1,LEN(CityName))+'.',
    CHARINDEX('.',SUBSTRING(REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)+1,LEN(CityName))+'.'),len(CityName))),1,1,'')+SPACE(1)+
    REVERSE(LTRIM(RTRIM(LEFT (REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)-1)))))
    FROM @City WHERE CHARINDEX('.',CityName) > 0;
    CityName RenumberedCityName
    1. Egypt Egypt
    1.1. Cairo 1. Cairo
    1.1.21. New Cairo 1.1. New Cairo
    1.1.21.5. Alexandria 1.1.21. Alexandria
    -- USING hierarchyid method
    SELECT
    CityName, RenumberedCityName=
    LTRIM(REPLACE(STUFF(CONVERT(hierarchyid,'/'+REPLACE(LEFT(CityName, CHARINDEX(' ', CityName)-1),'.','/')).GetAncestor(1).ToString(),1,1,''),'/','.')
    +SPACE(1)+REVERSE(LTRIM(RTRIM(LEFT (REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)-1)))))
    FROM @City WHERE CHARINDEX('.',CityName) > 0;
    CityName RenumberedCityName
    1. Egypt Egypt
    1.1. Cairo 1. Cairo
    1.1.21. New Cairo 1.1. New Cairo
    1.1.21.5. Alexandria 1.1.21. Alexandria
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Maybe you are looking for

  • How can I run a java program on Linux?

    I have JBuilder's IDE installed on my Linux partition and it works. However I don't know how to compile and test a program without it. Also I tried to install Limewire on Linux and although I've installed the Java SDK on the system. Once before I ins

  • After export movies works and then is not working anymore?!

    Hi guys, i am capturing HD movies to my final cut express HD..Edit them, expert as quick time movie (option self contain is OFF). Then i test the movies and they are like they should be. Then i import them into IDVD and IDVD accept some and some not.

  • Smart Playlists not updating

    Yesterday I added two new songs to my library. One of them should have gone into Smart Playlist "A," one of them into Smart Playlist "B," and both of them into Smart Playlist "C." For reasons that I am unable to understand (after reviewing the condit

  • What file formats should I use for maps?

    I've come to the IL forum simply because of the number of file formats IL will process.  My question however is more generic to file formats. I work with a large local county government (just as a citizen) and one of the projects we're working on is

  • Multiple Oracle Connexions In A Script

    Hi, I am actually encounter some problems with my oracle connexions. I need to have multiple opened connexions with differents user logons on a same database in a script . When I configure the second connexion, I could no more make request on the fir